ajax networkerror,Ajax NetworkError: A network error occurred

问题

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值