Jump to content

JSON parse problem


itwhiz

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 ???

 

 

Link to comment
Share on other sites

  • 8 months later...

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...