I have a very simple ajax GET request in jquery that works just fine on my local test server. If I move the web page to a hosted server (GoDaddy) along with the php service it fails with a textStatus = "error"
and errorThrown = ""
. Chrome displays
net::ERR_EMPTY_RESPONSE.
This all happens within 1 second so it's not a timeout issue.
If I truncate the number of records so the json returned is less than 1MB it works fine.
If I call the server code from GoDaddy webpage to my local server for all records (1.8MB) all is fine too. The good returns from either site will complete in less than a second.
What could be causing GoDaddy to basically return no data when the json echo has more than 1MB of data in it?
The php server routine:
if (isset($_REQUEST['_SESSION'])) die("Get lost Dweeb!");
error_reporting(E_ALL | E_STRICT);
header('Access-Control-Allow-Origin: *');
$date_code = $_GET['date_code'];
$region = $_GET['region'];
$chargers = array();
$chg_count = 0;
$ftime = filemtime("chargers.json");
if ($ftime != $date_code) {
$aTeslaChargers = json_decode(file_get_contents("chargers.json"),true);
foreach($aTeslaChargers as $aTeslaCharger) {
if ($aTeslaCharger['region'] == $region) {
$chargers[] = $aTeslaCharger;
$chg_count++;
//if ($chg_count > 1972) break;
}
}
}
$json = json_encode(array(array("date_code" => $ftime), $chargers));
echo $json;
The javascript routine:
var url = 'https://www.website.com/get_data.php?date_code=0®ion=north_america';
var jqxhr = $.ajax({
url: url,
type: "GET",
crossDomain: true
})
.done(function(response) {
console.log(new Date());
//var data = $.parseJSON(response);
//console.log(data);
console.log(response.length);
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log(new Date());
console.log(errorThrown);
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…