问题
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