0

Hi,

I have looked at this code and I cannot see the problem. If anyone can spot the error then I will be very grateful.

Basically I am returning an array from a .PHP in json format the code is here.

echo json_encode($anarray);

the array is made up like "vegetable" => "leek" etc etc.

Now when the array is echo'd back onto the page for the jQuery to pick up I use this code.

    $.post('../ajax/list.php', {"test":"test"} , function(data)
    {
        $.each(data ,function(name,value)
        {   
            console.log(name + '=' + value);
        });
    });

Now the json object (data in the above code) returns this

"[{vegetable":"leek" , "price":50}]

This is as expected but when run over the $.each all that happens is it says invalid identifier.

There must be a simple error there but so far I cannot spot it. Can anyone else see it?

Thanks

Noel.

3
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by Airshow
0

I tried all the usuals like (i, elm) or (key,name) or (a,b) none worked. I really cant work this one out.

0

Try specifying 'json' as $.post's 4th parameter. Without it, jQuery will make an "intelligent guess", which means it may get it wrong.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.