Using JSON with Ajax
Using JSON with Ajax is very straightforward, simply invoke String#evalJSON on the transport’s responseText property:
new Ajax.Request('/some_url', {
method:'get',
onSuccess: function(transport){
var json = transport.responseText.evalJSON();
}
});
If your data comes from an untrusted source, be sure to sanitize it:
new Ajax.Request('/some_url', {
method:'get',
requestHeaders: {Accept: 'application/json'},
onSuccess: function(transport){
var json = transport.responseText.evalJSON(true);
}
});
本文介绍如何使用Ajax请求JSON数据,并通过evalJSON方法解析响应文本。此外还强调了当数据来源不可信时,需要进行数据净化处理。
1626

被折叠的 条评论
为什么被折叠?



