如何通过jquery设置jsonp回调来检索restful web服务数据
我问了一个关于 firebug 上无效标签的问题,当我尝试从我的 Restful Web 服务检索数据时会发生这种情况。我收到的大部分答案都是关于设置回调函数。但我似乎无法从中获得正确的果汁。你能告诉我一个具体的代码来说明如何做到这一点吗?或者至少更正此处的代码:
type: "GET",
cache: false,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
processdata:true,
jsonp: false, jsonpCallback: "success",
url: 'http://localhost:8732/Service1/data/10',
success : function success(data) {
jsonResponse = eval("(" + data + ")");
alert(jsonResponse)
},
error : function(req,status, ex) {
alert(ex);
}
谢谢,
I have asked a question regarding invalid label on firebug which happens when I try to retrieve data from my restful web service. Most of the answers I received was about setting a callback function. but I can't seem to get the right juice from it. can you show me an exact code on how to do it? or atleast correct the code here:
type: "GET",
cache: false,
contentType: "application/json; charset=utf-8",
dataType: "jsonp",
processdata:true,
jsonp: false, jsonpCallback: "success",
url: 'http://localhost:8732/Service1/data/10',
success : function success(data) {
jsonResponse = eval("(" + data + ")");
alert(jsonResponse)
},
error : function(req,status, ex) {
alert(ex);
}
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哇,你那里有很多不必要的东西。试试这个:
jQuery 将处理 url 上的回调。请参阅此处: http://api.jquery.com/jQuery.ajax/
更新
为什么是jsonp?如果您从 localhost 获取此信息,为什么不只是 json 呢?正如下面的评论中所讨论的,您的服务器当前无法执行 jsonp 响应,但它可以执行 json。
Wow, you've got a lot of unnecessary stuff there. Try this:
jQuery will take care of the callback on the url. See here: http://api.jquery.com/jQuery.ajax/
UPDATE
Why jsonp? If you're getting this from localhost, why not just json? As discussed in the comments below, your server currently is not capable of a jsonp response, but it can do json.