I've found a few posts (here and across the web) on this issue and tried the proposed solutions with no success, but there were some differences in the original issue. My example seems very straightforward, so I'd love to get some input on this. Here's the code:
theURI = "https://<?= $_SERVER['HTTP_HOST'] ?>
/validate.php";
theData = {
'validationType' : 'login',
'ident' : document.getElementById("login_ident").value,
'password' : document.getElementById("login_pw").value,
'loginTries' : <?= $loginTries ?>
}
$.getJSON(theURI, theData, function() {alert('Success!')});
The "Success!" alert shows up fine but the error "Failed to load resource: cancelled" flashes through the error console. "validate.php" is as follows (some of the server code has been omitted for clarity), assume the variables are all basically valid values:
<?php
echo '{';
echo '"result" : "' . $login_success . '",';
echo '"loginTries" : "' . $loginTries . '",';
echo '"feedback" : "' . $loginFeedback . '",';
echo '"feedbackClass" : "' . $loginTextClass . '",';
if($login_success) {
echo '"userData" : {';
$firstPass=true;
foreach ($g_aUserData as $theKey => $theValue) {
if(!$firstPass) echo ","; else $firstPass=false;
echo '"' . $theKey . '" : "' . $theValue . '"';
}
echo '}';
}
echo '}';
?>
Which generates (sample data, of course):
{"result" : "1","loginTries" : "0","feedback" : "SUCCESSFUL LOGIN!","feedbackClass" : "login_text","userData" : {"firstName" : "Gomez","memberID" : "39203","lastName" : "Aadams","lastLogin" : "","message" : "","credHash" : "3baf7a67271ecfd93kdsid33s2a65c16a9413f652"}}
Which reformats to:
{
"result" : "1",
"loginTries" : "0",
"feedback" : "SUCCESSFUL LOGIN!",
"feedbackClass" : "login_text",
"userData" : {
"firstName" : "Gomez",
"memberID" : "39203",
"lastName" : "Aadams",
"lastLogin" : "",
"message" : "",
"credHash" : "3baf7a67271ecfd93kdsid33s2a65c16a9413f652"
}
}
Any ideas? I've tried:
1) Loading the data into a querystring and omitting the data param entirely.
2) Changing the call to be relative.
3) Changing the "https" to "http".
UPDATE: OK. Based on comments, I paid my stupid tax and had the code generate the JSON data without any HTML trimmings. Strangely, I still am getting the same error. Tried the same fixes noted above, still not working.