GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Thursday, March 17, 2011

JSON - Response As An Array

When you hope your json response as an array, not as an object, so do it like this one:
Server:
    $data = array();
    $data[] = 'lady gaga';
    $data[] = 'luna maya';
    $data[] = 'barack obama';

    echo json_encode($data);

Client:
    $data = eval('('+ajax.responseText+')');
    for(i=0; i<data.length; i++){
        element.innerHTML = innerHTML + data[i];
    }
Share/Bookmark

No comments:

Post a Comment