I am using this jQuery basic ajax reader:
我正在使用这个jQuery基本的ajax阅读器:
$.ajax({
url: url,
dataType: 'jsonp',
success: function (data) {
console.log('data is', data);
}
});
The full server response I get is:
我得到的完整服务器响应是:
jQuery17107194540228229016_1350987657731({"action":"", "type":"", "callerId":""},
{"errorCode":0,"errorDescription":"OK","success":true,"payload":null});
However, when I try to output it with the console.log('data is,data);
the output I get is:
但是,当我尝试使用console.log('data is,data)输出它时;我得到的输出是:
data is Object {action: "", type: "", callerId: ""}
How do I receive the other part of the server response?
我如何收到服务器响应的其他部分?
ie: The part that tells me success:true
:
ie:告诉我成功的部分:true:
{"errorCode":0,"errorDescription":"OK","success":true,"payload":null}
2 个解决方案
#1
3
Try this, I don't know if it will help:
试试这个,我不知道它是否会有所帮助:
success:function(data, second){
console.log('data is',data, 'second is ',second);
As several people has pointed out, the success function will only return if the request is a success. But if you have some special reason why you want to use those return values, you could add an extra parameter ( I think, still haven't tested it myself ).
正如几位人士指出的那样,只有在请求成功的情况下,成功函数才会返回。但是如果你有一些特殊的原因想要使用这些返回值,你可以添加一个额外的参数(我想,仍然没有自己测试过)。
#2
1
success callback from jquery request will always be success even if the response is a 404. As long as the server was reachable, that is always a success. Only when server is not reachable or request got lost in the way the error callback is triggered. From that perspective, you'll always have to analyze the output to see if the result is the desired (that or check the status code of the response. If it's 40x, then it's probably an error from your perspective).
即使响应是404,来自jquery请求的成功回调也将始终成功。只要服务器可以访问,这总是成功的。仅当服务器无法访问或请求以错误回调被触发的方式丢失时。从这个角度来看,你总是必须分析输出以查看结果是否是所需的(或检查响应的状态代码。如果它是40x,那么从您的角度来看可能是错误的)。
#1
3
Try this, I don't know if it will help:
试试这个,我不知道它是否会有所帮助:
success:function(data, second){
console.log('data is',data, 'second is ',second);
As several people has pointed out, the success function will only return if the request is a success. But if you have some special reason why you want to use those return values, you could add an extra parameter ( I think, still haven't tested it myself ).
正如几位人士指出的那样,只有在请求成功的情况下,成功函数才会返回。但是如果你有一些特殊的原因想要使用这些返回值,你可以添加一个额外的参数(我想,仍然没有自己测试过)。
#2
1
success callback from jquery request will always be success even if the response is a 404. As long as the server was reachable, that is always a success. Only when server is not reachable or request got lost in the way the error callback is triggered. From that perspective, you'll always have to analyze the output to see if the result is the desired (that or check the status code of the response. If it's 40x, then it's probably an error from your perspective).
即使响应是404,来自jquery请求的成功回调也将始终成功。只要服务器可以访问,这总是成功的。仅当服务器无法访问或请求以错误回调被触发的方式丢失时。从这个角度来看,你总是必须分析输出以查看结果是否是所需的(或检查响应的状态代码。如果它是40x,那么从您的角度来看可能是错误的)。