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?



Recommended Answers

All 3 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.