错误:: jQuery没有被调用

这是我的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); } }); 

来自我的示例url的回复

  { "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 } 

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

 jQuery180014405992737595236_1357861668479 was not called 

更新

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

 No Transport 

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

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

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

那么正确的反应应该是这样的:

 nameOfCallbackFunction({"yourjson": "here"}); 

我知道这是一个旧线程,但一直在努力让跨域ajax示例工作。 我读了很多关于使用dataType:jsonp和support.cors = true但得到了200 – 成功但是一个解析错误。

然后,我在这篇post中读到了关于使用其中一个的信息。 然后我将dataType:更改为json并离开support.cors = true并且它工作正常。 最后。 。 。

这可能会帮助遇到相同问题的其他人。

你有错误JQueryXXXX的原因是你正在调用的url中有一个错误,你需要引入“?callback =?”,所以看起来像:

 "http://example.com/v1/search?callback=?keyword=r" 

另外如果你打电话给.php,请记住:

 header('Content-Type: application/json; charset=utf8');