---
title: "prototype+json ajax应用"
author: "wiseboyloves"
date: "2010-08-24T23:13:55Z"
tags: []
categories: ["企业架构"]
slug: "prototype-json-ajax"
draft: false
lastmod: "2010-08-24T23:13:55Z"
id: 746408
url: "https://wiseboyloves.iteye.com/blog/746408"
---

### Using JSON with Ajax

Using JSON with Ajax is very straightforward, simply invoke [`String#evalJSON`](http://blogger.org.cn/api/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); 
  } 
});
```