[英]Accessing cross-domain data using jsonp
Well, I'm trying to access php web service (returning jsonp and url format is http://service.com/service.jsonp ). 好吧,我正在尝试访问php Web服务(返回jsonp和url格式为http://service.com/service.jsonp )。 First it was failing silently.
首先,它无声地失败了。 So, I tried debugging following code in direct Visual Studio and IE.
因此,我尝试在直接Visual Studio和IE中调试以下代码。
<script type="text/javascript">
$(document).ready(function () {
$('#btnClick').click(function () {
$.ajax({
url: "http://url.jsonp",
dataType: "jsonp",
jsonp: "data",
jsonpCallback: "jsonpcallback"
});
function jsonpcallback(data) {
alert('doinng it now');
}
});
});
</script>
After click, the data comes in VS (which is a correct jsonp output) but VS throws an error. 单击后,数据进入VS(这是正确的jsonp输出),但VS引发错误。 Following is the result:
结果如下:
Copy code 复制代码
data({"code":001,"msg":"true","data":{"obj1":"val1","obj2":"val2"}})
Error in VS: Microsoft JScript runtime error: 'data' is undefined VS中的错误:Microsoft JScript运行时错误:'data'未定义
It seems, that the return from the server is wrong. 看来,从服务器返回的消息是错误的。 Given your jQuery parameters, the result should look like
jsonpcallback({...})
. 给定您的jQuery参数,结果应类似于
jsonpcallback({...})
。 Can you check, that the requested URL is this: 您能否检查所请求的URL是这样的:
http://url.jsonp/?data=jsonpcallback
If it is, the server-side does it wrong and mixes the GET parameter name with its value. 如果是这样,则服务器端会出错,并将GET参数名称与其值混合在一起。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.