我有以下的JSON结构,正在从一个AJAX调用返回(伪值)
I have the following JSON structure, being returned from an AJAX call (pseudo values)
[
{
"id":"14",
"product_title":"Foo Bar v1.2",
"discount":"10% Off - New price: $97",
"vendor":"foobar"
}
]
下面是我的AJAX程序。
Here is my AJAX routine.
$.post('Ajax.php',function(res){
alert(res.product_title);
});
},'json');
然而,警报说未定义,即使它显然不是(萤火虫)。
However, the alert says "Undefined", even though it is clearly not (Firebug).
我试着做一个 $每();
上的资源,它出现的唯一钥匙中有0
I tried doing a $.each();
on the res, and it appears the only "key" in there is "0".
我在做什么错在这里?是它的方式,我处理的结构?干杯!
What am I doing wrong here? Is it the way I am processing the structure? Cheers!
尝试:
var j = res.pop(); // this will extract the `object` form the `array`
console.log(j.product_title);
您也可以这样写:
res.pop().product_title;