问题描述
var url="http://fsa.citop.in/lnct/service/signProcess.aspx";
var data={txtLogId: "[email protected]",txtLogPass: "xyz",hdnReqType2: "sign87162"};
var success=function(data, textStatus, jqXHR) {
console.log(data);
};
var fail=function(jqXHR, textStatus, errorThrown) {
console.log("Error:" + errorThrown );
}
$.ajax({
type: "POST",
url: url,
data:data,
success:success,
error:fail,
});
此POST请求在页面' http://的控制台中给我错误SyntaxError: Unexpected token < in JSON at position 4
. fsa.citop.in/lnct/'在Chrome中.
This POST request gives me the error, SyntaxError: Unexpected token < in JSON at position 4
, in the console of the page 'http://fsa.citop.in/lnct/' in chrome.
但是如果我使用fsa.citop.in/lnct/service/signProcess.aspx
(即没有http://),它不会给我带来任何错误,但数据不会返回任何内容.在POST请求的success
上,需要一个JSON对象.请有人解释这里发生了什么以及如何解决.
But if I use fsa.citop.in/lnct/service/signProcess.aspx
(i.e. no http://), it gives me no error, but nothing comes back in data. On success
of POST request, a JSON object is expected. Please somebody explain what is happening here and how it could be resolved.
推荐答案
最有可能是因为响应是HTML,并且正在尝试将其解析为其他内容.位置4上的<
是第一个<的<!DOCTYPE html...
.
It's most likely because the response is HTML and it's trying to parse it as something else. The <
at position 4 is the first < of <!DOCTYPE html...
.
您应该尝试在ajax调用中指定dataType(请参见 http://api.jquery.com /jquery.ajax/),并使signProcess.aspx
返回更有用的内容(当前响应内容类型为application/json
,但它会打印HTML).
You should try to specify dataType in your ajax call (see http://api.jquery.com/jquery.ajax/) and also make signProcess.aspx
to return something more useful (currently the response content type is application/json
but it prints HTML).
这篇关于意外令牌<在JSON中的位置4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!