Jump to content

JSON parse problem

Recommended Posts

Hope this is the correct place for this question.

Developed a system on my Laptop (Win10 WAMP server connecting to SQL Server etc) working fine for all the XMLHTTPRequests', but when I put the same code on the main server (Linux, Using LAMP and connecting to SQL Server ) I get the following error from the  XMLHTTPRequests

"VM49:1 Uncaught SyntaxError: Unexpected token < in JSON at position 0". 

Clicking on the VM49:1 I can see the returned value from the JSON.parse and it has the correct values, but also contains   <!--        --> at the beginning just as though there should be a comment in there. 

Any ideas on how to get rid of this error ???



Share this post

Link to post
Share on other sites

The error is within your server side, when there's an error on your server side, the response comes with html tags '<' when there's an error php will add tag with the error message. Therefore your json contains the html tags and becomes invalid because of unexpected tags.

if you have an array with semi colon, at last value description please remove that and try again  

for example :

if you have array like this: 

$eventstArray[] = array
            'label'         => $eventsQuery2['eventTitle'];
            'venue'         => $eventsQuery2['venueName'];
            'category'      => $eventsQuery2['catDesc'];
            'price'         => $eventsQuery2['eventPrice'];
            'description'   => $eventsQuery2['eventDescription'];

it should be like this:

$eventstArray[] = array(
            'label' => $eventsQuery2['eventTitle'],
            'venue' => $eventsQuery2['venueName'],
            'category' => $eventsQuery2['catDesc'],
            'price' => $eventsQuery2['eventPrice'],
            'description' => $eventsQuery2['eventDescription']

 just remove last semi-colon

Share this post

Link to post
Share on other sites

Please do not reply to old topics.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...