当前位置: 代码迷 >> JavaScript >> prototype+json ajax使用
  详细解决方案

prototype+json ajax使用

热度:91   发布时间:2012-10-08 19:54:56.0
prototype+json ajax应用

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); 
  } 
});
?
  相关解决方案