| Page 1 of 1 | [ 6 posts ] |
|
Hello!
PHP Horizons | PHP Horizons Blog | Gran Turismo 5 Power
The problem I have is the JSON data I'm pushing out to the DataSource validates fine using JSLint, but is getting an error in the script. I do have a repro to link to. It'll take a couple steps to get to it. http://test.tycoonrats.com/lib/js/business.js (the js script is there, the page that uses it is below, I've made a demo account) http://test.tycoonrats.com/login.php User Name: demodemo Password: demodemo Once logged in, click this next link: http://test.tycoonrats.com/index.php?p=business_list (or click [Business List] on the left hand vertical menu) Click the "View the super panel" link on the next page. It will initiate an ajax request to a page that sends out some data used to initialize a DataTable and a DataSource. I've checked the JS code using JS Lint and I've gotten it to validate using all of the recommended settings except for "Disallow leading _ in identifiers" and using "YAHOO,document" as predefined variables. I've also checked the JSON response using JS Lint and it validates as a JSON object. The first time I copied the ajax response text containing the JSON object out of FireBug and attempted to validate it, it failed due to two line breaks. When I loaded up the ajax page through a normal request and viewed the source, and copied that instead, it validated no problem. That's the only clue I have found as to what is causing the JSON to fail, but since the output provided by this page (requires the demo account login to access...) [http://test.tycoonrats.com/index.php?a=business_list&case=data_source&sort=id&dir=asc&startIndex=0&results=25] validates just fine. Please help! Thank you! I rarely get stumped on something, but this one beats me. Oh, and I put in the -debug YUI includes and there is a Logger on the screen. Cheers! |
|
JSLint will Ok invalid JSON. JSON is not simply JavaScript, it has further restrictions so that it will be portable across other platforms. JavaScript will take either single or double quotes, JSON only accepts double quotes. JSON requires all property names to be enclosed in quotes, JavaScript does not as long as those identifiers do not contain invalid characters.
The DataSource contains a built-in JSON decoder. If the JSON utility is not loaded, it will use its built-in one, which is nothing more than a plain JavaScript eval(). The decoder in the JSON utility is more strict and will not accept invalid JSON which is still valid JavaScript. Try the same program without the JSON utility and it will probably work. See: http://json.org/ and test with: http://www.jsonlint.com/ |
|
Thanks for your reply Satyam. Your article on the DataTable has been a tremendous help.
PHP Horizons | PHP Horizons Blog | Gran Turismo 5 Power
I should have been more specific on the validation I performed on the JSON object. I did use http://www.jsonlint.com/ to validate the JSON object sent from the server and I used http://www.jslint.com/ to validate the javascript script. Both passed their respective validations. I would remove the YUI JSON module, except that the script makes extensive use of it elsewhere. Thanks again, and any further suggestions from ya'll are greatly appreciated! |
|
I've just checked your data and, indeed, it does validate as JSON so there is no point in removing the JSON component. The table definition seems to come as a JSON message as well and it would seem to match the data structure. However, checking in the Logger, I can see it says:
Error: DataSource instance0 JSON data could not be parsed: and then it shows what it actually read, as far as it understands it, so there is definitely something in that message that bothers the JSON parser or the DataSource. If you can find it and see who's problem is it, I'm sure that either the JSONLint guys or the DataSource and/or JSON guys will like to know whose fault is it. Since you are loading the YUI files from your own server and it seems difficult to find the line sending that error message to the logger in all that big source all chained together, perhaps if you locate the message in the source and put a debugger; statement right before it, you might find out easily what is the origin of that complain. |
|
Thanks again Satyam!
PHP Horizons | PHP Horizons Blog | Gran Turismo 5 Power
That gives me confidence my code is not in error, which in turn means I can really dig into that JSON object, like you're saying, and find out what part isn't working out. I'll definitely look into that very soon. Thanks again for looking at that looooooooong bit of code and verifying with me that the JSON I was using was fine. |
|
The problem turned out to be a problem with the JSON object I sent out. I had the data nested one step deeper than it should have been by wrapping a few things in a PHP array( ... ) when it should not have been.
PHP Horizons | PHP Horizons Blog | Gran Turismo 5 Power
Thanks for all the help with this! |
| Page 1 of 1 | [ 6 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group