---
title: "jquery1.5出现的ajax返回json格式错误问题"
author: "baowp"
date: "2011-03-19T11:11:05Z"
tags: ["Ajax", "jQuery", "json"]
categories: ["Web前端"]
slug: "jquery1-5-ajax-json"
draft: false
lastmod: "2011-04-17T15:26:01Z"
id: 967330
url: "https://baowp.iteye.com/blog/967330"
---

前几天将工程里的jquery1.4.4更新为jquery1.5.1,发现原先ajax提交dataType为json的,发生了错误.

      后经过反复调试,原来是jquery1.5和现在的jquery.validate.js不大兼容,validate.js改写的$.ajax会使jquery1.5返回的json加载到&lt;script&gt;标签中执行.所以没有引入validate.js的页面都是正常的

      解决方法可以将dataType设为默认,然后自己写$.parseJSON(data)去转,

      更好的方法为修改dataType:"json"为dataType:"text json",如下

    jquery 1.4.4

```
$.ajax({
		url: url,
		dataType:"json",
		success: function(data){
			console.info(data.property);
	    }
	});
```

   jquery 1.5.1

```
$.ajax({
		url: url,
		dataType:"text json"
	}).success: function(data){
		console.info(data.property);
	}
```