错误:: jQuery未被调用

iJa*_*ade 15 javascript ajax jquery cross-domain

这是我的ajax电话.

 $.ajax({
    type: "GET",
    url: "http://example.com/v1/search?keyword=r",
    dataType: "jsonp",
    crossDomain: true,
    success: function (responseString) {
        alert(responseString);
    },
    error: function (xhr, errorType, exception) {
        var errorMessage = exception || xhr.statusText;
        alert(errorMessage);
    }
});
Run Code Online (Sandbox Code Playgroud)

来自我的示例网址的回复

    {
    "response": [{
        "attributes": {
            "type": "enge",
            "url": "/services/data/v24.0/sobjects/Challenge__c/a0GZ0000005Vvh4MAC"
        },
        "name": "Really",
        "end_date": "2013-02-07T15:26:00.000+0000",
        "total": 350.0,
        "registered_members": 0.0,
        "id": "30",
        "type": "Design",
        "id": "a0GZ0000005Vvh4MAC",
        "start_date": "2012-11-19T16:52:00.000+0000",
        "description": "This is my really cool challenge",
        "remaining_days": 28.0,
        "categories__r": [{
            "attributes": {
                "type": "Category__c",
                "url": "/services/data/Category__c/a08Z0000000RNI2IAO"
            },
            "id": "0RNI2IAO",
            "display_name": "Andy"
        }, {
            "attributes": {
                "type": "Category__c",
                "url": "/services/Category__c/a08Z0000000RNI3IAO"
            },
            "id": "a0O",
            "display_name": "ADR"
        }]
    }

    }],
    "count": 1
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试进行跨域调用并收到错误

jQuery180014405992737595236_1357861668479 was not called
Run Code Online (Sandbox Code Playgroud)

更新

好吧,我试图使用dataType:"json",但在那一点上得到错误

No Transport
Run Code Online (Sandbox Code Playgroud)

Que*_*tin 10

这表明网络错误或不返回JSONP响应的终点.

(我猜测我在测试时遇到的DNS查找失败是因为那不是你真正的URL(请使用example.com例如URL,这就是它的用途),如果没有,那就是你的问题).


Chr*_*oph 5

这是一个不正确的 JSONP 响应。服务器需要处理请求的callback=nameOfCallbackFunction参数GET并将其作为函数包装器提供。

正确的响应应该如下所示:

nameOfCallbackFunction({"yourjson": "here"});
Run Code Online (Sandbox Code Playgroud)