“Invalid Label” JSON error from $.POST method – The WordPress “Login With Ajax” Dilema
Upgrade your jQuery
- Hey having this problem? Update your jQuery!
**I used version 1.8.3. looks like this is fixed now in v1.6, after upgrading the issue disappeared. - Have an updated jQuery installed?
Make sure you aren’t overriding it with a different jQuery version!
That’s my quick answer to my problem after spending a good amount of time on it, but I suppose I can be more verbose. This all started when we had this implemented on an initial version of a site. After getting a new theme and a new environment to implement it in, it stopped working. This was frustrating because we had the current jQuery installed, but it just wouldn’t behave in the new theme we were working in. This turned out to be because it was being overwritten by the version of jQuery that was needed to make the rotator plugin work.
While I’m writing this, I may as well mention all the other solutions I came across that appeared to be pretty legit:
Incorrect labeling syntax.
Names have certain rules when creating an object literal. Names cannot start with a number, be any of reserved keywords, or include special characters (except an underscore or dollar sign). Values can be a string, number, object, array, boolean, or null.
Are your HTTP headers set to json? **Resource
<?php header('Content-type: application/json');
Do you have a validation plugin installed? **Resource
jQuery’s Validation plug-in is not compatible with jQuery 1.5, removing the plug-in yields to the right behaviour.
Wrap the JSON string in parenthesis **Resource
The problem occurs because eval is interpreting the first item in the JSON string as a JavaScript Label. The solution is to wrap the JSON string in parenthesis.
This is the answer that I was in essence pursuing, and it did indeed get rid of my errors. It also seemed in most cases that it would have worked for this situation. However, since this was in a plugin I didn’t write, there was a lot of places I’d have to rewrite the code to accommodate the JSON being in those parenthesis. Turned out to be more work than it was worth.
Overall, seems like this is avoided by making sure your using a later version of jQuery. Hopefully this creates some good documentation on this issue.