简体   繁体   English

jQuery-调用ajax返回错误

[英]jquery - calling ajax returns error

I'm currently attempting to perform an ajax request through jquery to fetch some data from a server. 我目前正在尝试通过jquery执行ajax请求,以从服务器获取一些数据。 However, whenever calling $.ajax , it brings up this error. 但是,每当调用$.ajax ,都会引发此错误。

在此处输入图片说明

The weird thing is, whenever calling $.ajax without any attributes, which should be valid, it still brings up the same error. 奇怪的是,每当调用没有任何属性的$.ajax应该是有效的)时,它仍然会引发相同的错误。 I'm using the latest version of jquery, 3.1.1 , and not using the slim build. 我正在使用最新版本的jquery 3.1.1 ,而不是使用苗条的构建。

Thanks in advance. 提前致谢。

My Ajax: 我的Ajax:

$.ajax({
    url: url,
    method: 'GET',
    mimeType: 'text/plain',
    success: function(url, status) {
        // on success
    },
    error: function(error, status) {
        // on error
    }
});

Apologize for the inconvenience, 不便之处敬请谅解,

As it turned out, jquery 2.2.4 worked just fine. 事实证明,jQuery 2.2.4正常工作。 Appears that it might be the fact that I'm not quite up to date with the new versions. 看来这可能是因为我不太了解新版本的事实。

If you still wish to use jQuery >= 3.0 then you will have to manage your errors differently. 如果您仍然希望使用jQuery> = 3.0,那么您将不得不不同地管理错误。

The jqXHR object returned from jQuery.ajax() is a jQuery Deferred and has historically had three extra methods with names matching the arguments object of success, error, and complete. 从jQuery.ajax()返回的jqXHR对象是jQuery Deferred,并且在历史上曾经有三种额外的方法,它们的名称与成功,错误和完成的参数对象匹配。 This often confused people who did not realize that the returned object should be treated like a Deferred. 这常常使那些没有意识到应该将返回的对象视为延迟对象的人们感到困惑。 As of jQuery 3.0 these methods have been removed. 从jQuery 3.0开始,这些方法已被删除。 As replacements, use the Deferred standard methods of done, fail, and always, or use the new then and catch methods for Promises/A+ compliance. 作为替代,使用完成,失败和始终使用延迟的标准方法,或使用新的then和catch方法来实现Promises / A +遵从性。

https://jquery.com/upgrade-guide/3.0/#breaking-change-special-case-deferred-methods-removed-from-jquery-ajax https://jquery.com/upgrade-guide/3.0/#breaking-change-special-case-deferred-methods-removed-from-jquery-ajax

And you can find more details concerning Deferred standard methods here: https://api.jquery.com/category/deferred-object/ 您可以在这里找到有关延期标准方法的更多详细信息: https : //api.jquery.com/category/deferred-object/

You will find an example of usage for errors in this post: Throwing an Error in jQuery's Deferred object 您将在本文中找到错误用法的示例: 在jQuery的Deferred对象中引发错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM