ITeye博客

prototype+json ajax应用

wiseboyloves · 2010-08-24 23:13 · struts学习之路 · 企业架构 · Markdown

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); 
  } 
});

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。