Mark H
Mark H

Reputation: 11

JSON Parse error from json_encode back to javascript

I am using JQuery to make an ajax request. In my php, I have an associative array. Here is the main portion of it:

$log = array('data','moredata');
$eventine = array('this','format');
$logID = array('another','array');
$data['log'] = $log;
$data['time'] = $eventtime;
$data['id'] = $logID;
echo json_encode($data);

When I return the json object. I use this portion of javascript to get the values:

//after getting data back from ajax call
x = JSON.parse(data);
       for (i = 0; i < x.log.length; i++) {
    results += x.time[i] +": "+x.log[i];
    results += "<br />";
                    }

The code works perfectly. My complaint is that it is throwing an error in the browser's firebug and IE log. It says I have a JSON.parse error. I've looked everywhere online and couldn't find anything similar.

The strange thing is.This code is working. But it keeps saying there is an error.

If anybody could assist me and telling me what I've done wrong, I would be very grateful.If you need more information, I am happy to post more code. Never posted here before and not sure on limits.

Upvotes: 1

Views: 2628

Answers (1)

Martin Jespersen
Martin Jespersen

Reputation: 26183

Given your code you have a typo: $eventine = array('this','format'); but $data['time'] = $eventtime; maybe your problem is that x.time[i]in your js is invalid, since x.time is not an array like you pressume ?

Upvotes: 1

Related Questions