如何在通过jquery检索restful web服务数据时设置jsonp回调

如何在通过jquery检索restful web服务数据时设置jsonp回调,json,rest,jquery,jsonp,Json,Rest,Jquery,Jsonp,我问了一个关于firebug上的无效标签的问题,当我试图从RESTfulWeb服务检索数据时,会发生这种情况。我收到的大多数答案都是关于设置回调函数的。但我似乎无法从中得到正确的果汁。你能告诉我怎么做的确切代码吗?或者至少在此处更正代码: type: "GET", cache: false, contentType: "application/json; charset=utf-8", dataType: "jsonp",

我问了一个关于firebug上的无效标签的问题,当我试图从RESTfulWeb服务检索数据时,会发生这种情况。我收到的大多数答案都是关于设置回调函数的。但我似乎无法从中得到正确的果汁。你能告诉我怎么做的确切代码吗?或者至少在此处更正代码:

        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);
        }

谢谢,

哇,你那里有很多不必要的东西。试试这个:

$.ajax({
    url: 'http://localhost:8732/Service1/data/10',
    dataType: 'jsonp',
    error: function(req, status, ex) {
        // your code here
    },
    success: function(data) {
        //your code here
        // Please note: you don't need to 'eval' the json response.
        // The 'data' variable will be loaded with the object that the json string represents.
        // By the way, don't use 'eval', ever.
    }
});
jQuery将处理url上的回调。请看这里:

更新
为什么是jsonp?如果您是从localhost获得此信息,为什么不只是json?正如在下面的评论中所讨论的,您的服务器目前无法进行jsonp响应,但它可以执行json。

感谢您的回答。但我仍然有同样的结果。firebug上的标签{“Id”:10,“名称”:“Leo Messi”}无效。有什么想法吗?你没有在
success
功能中进行
eval
ing,是吗?请出示一些修改后的代码。这是我使用的代码。我读过关于评估的东西。是的,我没有评估成功。ajax({url:'',数据类型:'jsonp',错误:函数(req,status,ex){alert(“hi”);},成功:函数(data){console.log(data);})<代码>数据不是字符串。它是一个物体。这就是
console.log()
所扼杀的吗?更新:不是,因为函数接受对象。你能提供更多的信息吗?我想可以。对不起,我对json真的很陌生。我正在学习它。我只是想通过警报或控制台以某种方式显示数据。你能给我介绍一下这个吗?谢谢你的快速回复。更新:我想就是这样。错误是无效标签,它有一个小箭头指向“{ ID”:10,“名称”:“Leo Messi”}在{和Id.希望有帮助。