AJAX和JS,无法读取JSON数据?

I have the following AJAX code:

var ajax = new XMLHttpRequest();
axaj.open("POST", "index.php", true);
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

ajax.onreadystatechange = function(){
    if(x.readyState == 4 && x.status == 200){
        var returnVal = ajax.responseText;
    }
}

ajax.send("nextMax=-1");

And pairs with some PHP that ends with:

echo json_encode(array(
    'next_id' => $nextID
));

exit();

This all works, as it is. If I print out returnVal inside the AJAX call, it prints out the correct array, with the correct value:

{"next_id":"935210077606657948"}

But I cannot access the id directly. I've tried

var nextID = returnVal.next_id;

and

var nextID = returnVal['next_id'];

and other variations, but all return undefined.

How do I get the array elements from within returnVal?

Thanks in advance.

Found a solution not 30 seconds after posting the question. But for those who are in the same place:

Switch

var returnVal = ajax.responseText;

to

var returnVal = JSON.parse(ajax.responseText);

and then the call works:

returnVal.next_id;