日期:2014-05-16  浏览次数:20654 次

请教这个jquery哪里错的
$.ajax({
url:"http://localhost/paged/2",
type:"post",
dataType:"json",
data:{},
success:function(msg){
alert(msg);
$("#pends").css({display:"block",height:"auto"});
}

我dataType改成了json,alert什么都没有啊 ,怎么不能成功返回数据的?

------解决方案--------------------
访问http://localhost/paged/2看返回了什么。。

出错了或者非标准json格式的字符串在jq1.4+都会执行error回调,而不是success回调

$.ajax({
url:"http://localhost/paged/2",
type:"post",
dataType:"json",
data:{},
success:function(msg){
alert(msg);
$("#pends").css({display:"block",height:"auto"});
}
,error:function(xhr){alert('出错\n\n'+xhr.responseText)}/////

------解决方案--------------------
http://localhost/paged/2

返回的值 需要是json的标准格式, 需要是双引号
------解决方案--------------------
浏览器F12 看服务端响应了什么再作判断吧。
------解决方案--------------------



引用:
$.ajax({
url:"http://localhost/paged/2",
type:"post",
dataType:"json",
data:{},
success:function(msg){
alert(msg);
$("#pends").css({display:"block",height:"auto"});
}

我dataType改成了json,alert什么都没有啊 ,怎么不能成功返回数据的?

$.ajax({
url:"http://localhost/paged/2",
type:"post",
dataType:"json",
data:{},
success:function(msg){
alert(msg);
$("#pends").css({display:"block",height:"auto"});
}
})



------解决方案--------------------
http://localhost/paged/2返回的内容是json格式的吗
------解决方案--------------------
http://localhost/paged/2返回的内容是json格式的吗
同问
------解决方案--------------------

------解决方案--------------------
<result type="json" name="success">  
                <param name="contentType">text/html</param>  
            </result>
            <result type="json" name="error">  
                <param name="contentType">text/html</param>  
            </result>
在action里这样配置一下
------解决方案--------------------
dataType:"json",  不要了  先看下能返回数据吗
------解决方案--------------------
问题描述清楚啊, 先断点到控制层确保你的URL没有问题, 然后看方法有没有出错,再就是你是否对返回值进行json转换