问题

Just yesterday this code was up and running in my LAMP, I'm not sure if I could inflict any major changes. It's a simple ajax script that retrieves data from API.

Today it stopped work, the console just throws "NetworkError: A network error occurred.", even stranger is that when I tried the formatted GET query myself it all worked fine, API responded correctly.

http://localhost/uzduotis2/data/mobile/api/mobile.php?query%5Boperators%5D%5B0%5D=1&query%5Boperators%5D%5B1%5D=2&query%5Boperators%5D%5B2%5D=3&query%5Bmin%5D=180&query%5Bsms%5D=400&query%5Bmb%5D=128&query%5Bperks%5D=7&_=1385898696657

Well, I don't know what else I can do—maybe there was a way to make the error code more specific?... Anyway, here's the code:

function ajaxCall(url, req, req_type, async) {

return jQuery.ajax({

type: req_type,

url: url,

data: req,

contentType: "charset=utf-8",

dataType: 'json',

timeout: 30000,

async: async,

cache: false,

});

}

var ApiUrl = "http://localhost/uzduotis2/data/mobile/api/mobile.php";

$(document).ready(function() {

// .....

var req = {query: {operators: Operators, min: Min, sms: Sms, mb: Mb, perks:Perks}};

var promise = ajaxCall(ApiUrl, req, 'GET', false);

promise.success(function(out) {

console.log(out);

// populate(out);

});

promise.error(function(out){

console.log(out);

});

}

EDIT

I just found out that it works on another browser, must be a cache related issue, maybe somebody knows what could it be?

回答1:

you must return data in asynchrounous way so you must set async to true

var promise = ajaxCall(ApiUrl, req, 'GET', true);

来源:https://stackoverflow.com/questions/20312054/ajax-networkerror-a-network-error-occurred

ajax networkerror,Ajax NetworkError: A network error occurred相关推荐

  1. ajax进入error函数,报NetworkError: A network error occurred.

    现象: ajax调用失败进入error函数,但是java后端也不报错.追踪后发现以下报错:   js报错 - NetworkError: A network error occurred.   ngi ...

  2. ipad pro network error occurred

    如果 iPad Pro 出现网络错误,您可以尝试以下步骤: 检查您的 Wi-Fi 连接是否正常,确保您的 iPad Pro 正在连接一个可用的 Wi-Fi 网络. 尝试重启 iPad Pro 和您的路 ...

  3. mybatis:### The error may involve defaultParameterMap### The error occurred while setting parameter

    完整报错: Caused by: org.apache.ibatis.exceptions.PersistenceException:  ### Error updating database.  C ...

  4. mybatis报错### The error may involve defaultParameterMap ### The error occurred while setting paramete

    前两天写的一个springboot+mybatis的小项目在一个修改数据库数据的功能出现了 ###The error may involve defaultParameterMap ###The er ...

  5. AJAX 笔记 ajax

    自己用英文写的笔记,因为输入法切换太麻烦了 \(º □ º l|l)/ AJAX 1. Use Nodejs and Express the basic use of express // 1. im ...

  6. error An unexpected error occurred “httpsregistry.npmjs.orgd3-geo-proje

    error An unexpected error occurred: "https://registry.npmjs.org/d3-geo-proje yarn install 报错 大概 ...

  7. error An unexpected error occurred: “https://registry.npmjs.org/d3-geo-proje

    error An unexpected error occurred: "https://registry.npmjs.org/d3-geo-proje yarn install 报错 大概 ...

  8. AJAX教程@ajax

    文章目录 1.AJAX 1.什么是AJAX 2.AJAX核心对象 - 异步对象(XMLHttpRequest) 1.什么是XMLHttpRequest [简称为 xhr] 2.创建 异步对象 (xhr ...

  9. ajax - post(),AJAX中的$.post()函数

    回答 when(someAjaxDfd).then(function(data){/这里的参数为什么是data,因为在下面的ajax函数中,我把data当成resolve()的参数传过来了 someA ...

  10. Ajax,jQuery ajax,axios和fetch的区别

    Ajax,jQuery ajax,axios和fetch的区别 Ajax: Ajax 即"Asynchronous Javascript And XML"(异步 JavaScrip ...

最新文章

  1. Virtual host / experienced an error on node rabbit@wohu-rabbit and may be inaccessible
  2. Linux基础(二)--基础的命令ls和date的详细用法
  3. 代码优化实战:我又优化了一百个if else!
  4. 005_Java操作ZooKeeper
  5. mysql事务实战_MySQL - 实战 (2) - 事务隔离
  6. 阿里云主机安装Memcached扩展优化WordPress
  7. 【Android】invalidte和draw的方向
  8. Wordpress插件检测机制原理
  9. 基于vue自动化表单实践
  10. java编程50_java经典50编程题(1-10)
  11. Shell编程:Bash引号的那点事
  12. tomcat ---- jndi方式配置连接
  13. 【VC++类型转换】CString类型到Char[]类型的转换
  14. Unity编辑器扩展——自定义窗口
  15. spss分析方法-T检验
  16. 推荐top10的免费下载破解软件的网站
  17. 算法提高 字符串跳步
  18. STM32 控制蜂鸣器播放音乐的原理和实例
  19. 混频器/变频器的原理及分类
  20. React回调函数两种常用方式

热门文章

  1. IEEE论文检测的字体未嵌入问题Times New Roman,Bold, Times New Roman,Italic is not embedded解决方法
  2. n一加关闭小部件_小部件
  3. jpa 人大金仓数据库方言_人大金仓+springboot配置
  4. android xp 支付宝自动提现,支付宝商户如何自动提现?
  5. 前端工作中的一些解决问题的方法,可以参考一下
  6. Eat,PrayLove--结婚3周年
  7. stata基础使用教程(操作版)
  8. 互联网广告行业术语及缩写
  9. cnzz统计代码被谷歌浏览器拦截警告
  10. 机器人大冒险----leetcode