JSON对象未定义

I've got a an AJAX page request that uses a php file designed to handle queries to my MySQL database. The php file works just fine, but for some reason it's not being nice with me. Here's what I have:

    function updateForm(){
        ID = $('#listings').val();
        $.ajax({
            type: "POST",
            url: 'query.php',
            data: "query=true" +
                    "&id=" + ID,
            datatype: 'json',
            success: function(data) {
                alert(data);
                updatePreview();
            }
        });
    }

gives me a popup with:

{"results":[{"ID":"12","area":"Hoboken","bedrooms":"5","fullbath":"3","halfbath":"1","remarks":"No remarks to speak of.","sqft":"2500","photos":null,"price":"1000","fee":null,"realtor":"Jane Doe","phone":"555-555-5555","address":"10th & Willow","bix":"1"}]}

but as soon as I change it to:

    function updateForm(){
        ID = $('#listings').val();
        $.ajax({
            type: "POST",
            url: 'query.php',
            data: "query=true" +
                    "&id=" + ID,
            datatype: 'json',
            success: function(data) {
                alert(data.results);
                updatePreview();
            }
        });
    }

the popup just says undefined.

Ultimately, I want to parse out information and update my page accordingly, but I can't seem to access any of the properties of this JSON object. What's going on?

EDIT:

Here's the code from the php file:

if (isset($_POST['query'])){
    if (isset($_POST['id'])){
        $query = 'SELECT * FROM bix WHERE ID=' . get_post('id');
        $listing = mysql_query($query);
        print_json($listing);
    }
}
function print_json($var){
    $output = array();
    while($row = mysql_fetch_assoc($var)) {
        $output["results"][] = $row;
    }
    echo json_encode($output);
}

function get_post($var)
{
    return mysql_real_escape_string($_POST[$var]);
}

You should console.log(data) instead, with this you can see the keys that you can use to access the data.

Try using data instead of data.results or targeting the data.id or data.area and see what it comes up with

If it shows you a string in the alert popup it means that the data is a string, not JSON. For JSON it shows [Object object].

Check the response type. It should be applicaton/json or applicaton/javascript, not text/plain or something like that.

UPDATE: also make sure the server doesn't return the whole string in quotes. E.g. "[..]" - it just a string then. So use FireBug or Chrome Developer Tools to see what is the actual response. It might help to understand why jQuery doesn't handle it properly.

I don't think it's coming back as parsed json..it's coming back as a string I believe...

use:

var x = jQuery.parseJSON(data);
alert(x.results)

As Eugene pointed out, data is a string. Try eval:

var stuff = eval(data);
alert(stuff.results);

EDIT: this works, but jQuery.parseJSON is probably cooler.

did you try capitalizing the T in dataType, on the ajax call already?