语法错误:缺少;声明jQuery的JSONP前声明、语法错误、JSONP、jQuery

2023-09-12 21:16:28 作者:不念过去,不畏将来

我使用下面code访问托管在另一个域休息服务。

I am using below code to access rest service hosted on another domain.

$.ajax({
            type: 'GET',
            url: url,
            async: false,
            jsonpCallback: 'jsonCallback',
            contentType: "application/json",
            dataType:"jsonp",
            success: function(json) {
                alert(json);
            },
            error: function(e) {
               console.log(e.message);
            }
        });

我能够正确地获取数据,但我得到这个错误的萤火虫在Mozilla:

I am able to get the data correctly, but I get this error in firebug in mozilla:

语法错误:缺少;语句之前

SyntaxError: missing ; before statement

{你好:世界}

任何人都可以建议我什么,我做错了什么?即使JSON数据是有效的。我尝试了所有张贴在此建议question不过还是我收到同样的错误。

Can anyone suggest me what I am doing wrong here? Even though Json data is valid. I tried all the suggestions posted in this question But still I am getting same error.

推荐答案

如果它真的JSON你问,不设置JSONP的dataType ,并没有提供一个回调:

If it's really JSON you ask for, don't set "jsonp" as dataType, and don't provide a callback :

$.ajax({
        type: 'GET',
        url: url,
        contentType: "application/json",
        success: function(json) {
            alert(json);
        },
        error: function(e) {
           console.log(e.message);
        }
});