简体   繁体   English

jquery ajax总是抛出错误(永远不会成功)

[英]jquery ajax always throws error (never becomes success)

Below is my piece of code. 下面是我的一段代码。 My issue is the function on success never gets called. 我的问题是成功的功能永远不会被调用。 It always throws the error section. 它总是抛出错误部分。

$.ajax({ 
   url: 'http://localhost/zd/get_list',
   data: 'term=' + medical_provider, 
   dataType: 'json', 
   type: 'GET',
   success: function(data){
      alert('success');
   },
   error:  function(jqXHR, textStatus, errorThrown){
       alert(jqXHR);
  }
});

when i alert jqXHR is get [object Object] and when I alert textStatus I get "error" and when I alert errorThrown I get a blank error message. 当我警告jqXHR得到[对象对象],当我提醒textStatus时,我得到“错误”,当我提醒errorThrown时,我得到一个空白的错误消息。 I am using jquery 1.11.0. 我正在使用jquery 1.11.0。 I never get the success alert. 我从来没有得到成功警报。 Your help is greatly appreciated. 非常感谢您的帮助。

Also the the data returned in json is properly validated. 此外,json中返回的数据已正确验证。 I did a test on jsonlint. 我在jsonlint上做了一个测试。

Your get_list server-side functionality is erroring. 您的get_list服务器端功能get_list

Use chrome developer tools to breakpoint and inspect your jqXHR object in the error callback, it will have more details about what is going wrong. 使用chrome开发人员工具断点并在错误回调中检查你的jqXHR对象,它将有更多关于出错的细节。

Edit: - based on your updated comments, try adding: 编辑: - 根据您更新的评论,尝试添加:

contentType: 'application/json',

to your ajax call parameters 到你的ajax调用参数

So it turns out, the base url (was using codeigniter) was my computers ip address instead of localhost. 事实证明,基本网址(使用codeigniter)是我的计算机IP地址而不是localhost。 Accessing the through the ip addy OR changing the base url to localhost worked. 通过ip addy访问或将基本URL更改为localhost工作。 Thank you all for the help. 谢谢大家的帮助。

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

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