Skip to content Skip to sidebar Skip to footer

Php Files Sending Only A "parsererror" Through Ajax

SOLUTION: After a teamviewer session with @skobaljic he figured out that I was not actually opening the html in localhost but using the file system (as in file://...). I apologize

Solution 1:

You're not encoding valid JSON here.. This will give you a "parseerror" if you try using JQuery's $getJSON with it. Notice the JQuery Ajax Source from lines 275-281.

echo json_encode("0 results");

You could probably change it to something like:

echo json_encode(["0 results"]);

Solution 2:

You are using $.getJSON method, so the data is already parsed correctly. In case you do not get the JSON it would trigger fail.

So, just remove:

try { JSON.parse(data); } catch (e) { console.log('Not JSon') }

Post a Comment for "Php Files Sending Only A "parsererror" Through Ajax"