为什么无法访问JSON?

我有如下Ajax请求:

$.ajax({
    url    : '<?php echo current_url(); ?>',
    data       : "txtKeywords="+$("#txtKeywords").val()+"&search=Search For Item",
    type       : 'POST',
    dataType   : 'JSON',
    success : function(html)
    {       
        console.log(html);          
    }
});
return false;

控制台里有以下信息:

[{"productId":"5","productTitle":"Small Brasserie Dining Table","productPath":"small-brasserie-dining-table\/","productRangeId":"6","productSecondaryRangeId":"0","productTypeId":"2","productRefNo":"0080","productShortDesc":"","productBestSeller":"0","productFeatured":"0","productIsSet":"0","productPrice":"275","productSavingType":"none","productSavingPrice":"0","productSavingMessage":"","productDimWidth":"90","productDimHeight":"74","productDimDepth":"90","productTechnical":"Powder coated aluminium frame with welded joints.","productTemplateId":"5","productMetadataTitle":"","productMetadataKeywords":"","productMetadataDescription":"","productBandingColour":"grey","productActualPrice":"275","rangeTitle":"Dining","parentRangeTitle":"Aegean","fullRangePath":"aegean\/dining\/","fullProductPath":"aegean\/dining\/small-brasserie-dining-table\/","hasImage":"0"}]

但当我这样做时:

alert(html.productTitle)

我却只得到了未定义的东西?我哪里做错了?

Is it because your html variable is an array? Wouldn't you have to do...

alert(html[0].productTitle);

Try html[0].productTitle, I have run into this problem a few times.

Try using Jquery's JSON ajax function instead of the $.ajax it will parse the JSON for you.

http://api.jquery.com/jQuery.getJSON/

try doing something like this:

alert(html.d); // this will show the result of your ajax call

i don't know what the reason is to use the property 'd' but if you can take a look at your result, use a debug tool to see what data is getting back your ajax call.

if you want convert your JSON string to and object, you can do with the following code:

var respuesta = jQuery.parseJSON(html.d);