失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > ajax networkerror Ajax NetworkError: A network error occurred

ajax networkerror Ajax NetworkError: A network error occurred

时间:2020-11-05 09:44:17

相关推荐

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);

来源:/questions/20312054/ajax-networkerror-a-network-error-occurred

如果觉得《ajax networkerror Ajax NetworkError: A network error occurred》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。