Uncaught SyntaxError: Unexpected token < in>) at Object.

前端 未结 5 973
终归单人心
终归单人心 2020-12-20 16:57

i have an error in JSON.parse(), i have .php file which contain method to retrieve data from database and .js file for autoComplete function, my .php file return data as str

5条回答
  •  -上瘾入骨i
    2020-12-20 17:08

    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.

    The error is within this array

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

    it should be

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

    (The problem source was the semi-colon(;) after the description value. It should be only at the end of array)

提交回复
热议问题