您需要致电
$.parseJSON();
例如:
...success: function(data){ var json = $.parseJSON(data); // create an object with the key of the array alert(json.html); // where html is the key of array that you want, $response['html'] = "<a>something..</a>"; }, error: function(data){ var json = $.parseJSON(data); alert(json.error); } ...请参阅
http://api.jquery.com/jQuery.parseJSON/
如果仍然有斜杠的问题:搜索security.magicquotes.disabling.php
或:
function.stripslashes.php
注意:
此答案适用于那些尝试
$.ajax将
dataType属性设置为
json,甚至响应类型错误的人。
header('Content-type:application/json');在服务器中定义可以解决此问题,但是如果您要返回text/html或任何其他类型,则该
$.ajax方法应将其转换为
json。我做一个测试与旧版本的jQuery和唯一版本后
1.4.4的
$.ajax力的任何内容类型转换为
dataType通过。因此,如果您有此问题,请尝试更新jQuery版本。



