Thursday, 15 August 2013

jquery - Having a strange JSON Parsing issue -


I know there are so many questions of JSON parsing posted before, none of them are helping me is.

I am redirecting AJAX from PHP with AJAX to my page. According to JSONLint.com I am using valid JSON.

My issue every time I go to reach the properties of my object, as if they come back undefined. I console.log Jason object and it comes out right away. I'm confused!

PHP
  $ returnData [] = array ("trainingAccess" => "$ trainingAccess", "destinationUrl" => "$ destinationUrl", " Error message "= & gt;" $ error message "); Echo json_encode ($ returnData);   

JS
  $ .ajax ({type: "POST", url: "submit_login.php", data: {username: $ (" # Val (), Password: $ ("#password"). Val ()}, success: function (data) {var obj = JSON.parse (data); console.log (obj); // works warning (obj .destinationURL); // does not work.}   

solution

I was creating an array of arrays in PHP.

$ ReturnData = array ("trainingAccess" => "$ trainingAccess", "destinationUrl" => "$ destinationUrl", "error message" = & gt; "$ errorMessage");

Ajax Value, and it can parse it comes with the right content type.

Specify the data type so that you can make sure what is happening, then you know that the data is already in your Parsing for:

  $ .ajax ({type: "POST", url: "submit_login.php", data: {userName: $ ("# userName"). Val (), Password: $ ("# password") Val ()}, Data Type: 'Jason', Success: Joy Ction (Data) {console.log (data); Warning (data [0] .destinationUrl); }    

No comments:

Post a Comment