Javascript 错误 :: 未调用 jQuery

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14255502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 16:11:03  来源:igfitidea点击:

Error : : jQuery was not called

javascriptajaxjquerycross-domain

提问by iJade

Here is my ajax call.

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

Response from my example 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
}

i'm trying to make an cross domain call and getting error

我正在尝试进行跨域调用并出现错误

jQuery180014405992737595236_1357861668479 was not called

Update

更新

Well i tried to use dataType:"json" but at that point getting error

好吧,我尝试使用 dataType:"json" 但那时出现错误

No Transport

采纳答案by Quentin

That suggests either a network error or an end point that doesn't return a JSONP response.

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

(I'm guessing the DNS lookup failure I get when testing it is because that isn't your real URL (please use example.comfor example URLs, that is what it is there for) if not, then that is your problem).

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

回答by Christoph

It's an incorrect JSONP Response. The server needs to process the callback=nameOfCallbackFunctionargument of the GETRequest and serve it as a function wrapper.

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

The proper response then should look like this:

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

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

回答by Thomas DeVoe

I know this is an old thread but have struggled to get a cross domain ajax example working. I read much about using dataType: jsonp and support.cors = true but got a 200 - success but a parseerror.

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

I then read in this thread about using one or the other. I then changed the dataType: to json and left the support.cors = true and it worked. Finally . . .

然后我在这个线程中阅读了有关使用其中一个的内容。然后我将 dataType: 更改为 json 并保留 support.cors = true 并且它起作用了。最后 。. .

This may help someone else who encounters the same issue.

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

回答by Pablo Gutiérrez

The reason why you have the error JQueryXXXX is because there is an error in the url you are calling, you need to introduce "?callback=?", so looks like:

之所以出现JQueryXXXX错误,是因为你调用的url有错误,需要引入“?callback=?”,看起来像:

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

Also If you call a .php remember:

另外,如果您调用 .php,请记住:

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