views:

59

answers:

1

I'm originally a PHP programmer and have been struggling with this for at least 2 whole 9-to-5 days now. I've come a long way but I seem to have gotten stuck trying to figure out the last bit. It SHOULD be fairly simple, but somehow I can't seem to find anything that coulp help me figure it out.

I have the folliwing jQuery code that returns some values from the PHP backend:

    $.ajax({
    type: "POST",
    url: "KMS-backend.php",
    data: "&checkdivpage="+pagename ,
    success: function(data) {
        alert(data);
    }

This successfully alerts the returned JSON data:

[{"divid":"col-whole"},{"divid":"col-halfleft"}]

...Now what I can't seem to figure out, is how to turn this JSON object into an array, so I can loop the returned values! I can't even figure out how to return the first value seperately. Every answer I can find explains you can return each individual result with data[0], data[1], data[2] etc, like with a normal array, but this just returns the character in that position!

How can I return these values so that I can loop each of them seperately?

+2  A: 

set dataType

$.ajax({
    type: "POST",
    url: "KMS-backend.php",
    data: "&checkdivpage="+pagename ,
    dataType: 'json',
    success: function(data) {
        alert(data[0].divid);
    }
Luke Schafer
My GOD, that did it!!! At last! Thank you so much for the feedback guys, all 3 of your guesses were spot-on. You just saved me a headache, and with that, probably my computer and window glass :)THANK YOU!
Adrian van Vliet
You're welcome :)
Luke Schafer