首页 新闻 会员 周边

$.ajax post 方式提交请求,返回结果,为什么ashx程序已经执行完成,返回到error呢

0
悬赏园豆:15 [已解决问题] 解决于 2015-04-23 12:12

前端代码

function examine(t)
        {
            $.ajax({
                type: 'post',
                url: 'Ashx/Examine.ashx?id=' + t,
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status + "----" + XMLHttpRequest.readyState + "----" + textStatus);
                },
                success: function (result) {
                    alert(result);
                }
            });
            location.reload();
        }

后台ashx

public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if(context.Request.QueryString["id"]==null)
            {
                context.Response.Clear();
                context.Response.Write("参数错误");
                context.Response.End();
            }
            else
            {
                string id = context.Request.QueryString["id"];
                if(SqlHelper.UserInfo.Examine(Convert.ToInt32(id)))
                {
                    context.Response.Clear();
                    context.Response.Write("审核通过");
                    context.Response.End();
                }
                else
                {
                    context.Response.Clear();
                    context.Response.Write("审核失败");
                    context.Response.End();
                }
            }
        }

ashx代码已执行,就是会返回error

另外用firebug断点调试的时候有时候可以

吃俺老孙一棒的主页 吃俺老孙一棒 | 初学一级 | 园豆:38
提问于:2015-04-21 09:31
< >
分享
最佳答案
0

找到错了,妈蛋,我把location.reload()写到ajax外边就不行,得写到success里

吃俺老孙一棒 | 初学一级 |园豆:38 | 2015-04-23 12:11
其他回答(7)
0

你看看错误信息是啥?有可能是类型转换之类的错误。

收获园豆:2
幻天芒 | 园豆:37175 (高人七级) | 2015-04-21 09:59
-1

建议看一下返回的http状态码是什么?走error,说明http状态码不是200。

收获园豆:2
dudu | 园豆:31007 (高人七级) | 2015-04-21 10:33
0

孙猴子用post提交, 用 QueryString接收值, 我也是醉了。 

用Request.Form["ID"]才对, 阿弥陀佛~!

收获园豆:2
问天何必 | 园豆:3311 (老鸟四级) | 2015-04-21 10:39
0

自己调试一下看看啊,出了什么错?

你的代码能执行完吗,还是到

string id = context.Request.QueryString["id"];

if(SqlHelper.UserInfo.Examine(Convert.ToInt32(id)))

这个地方就出错了?

收获园豆:2
Albert Fei | 园豆:2102 (老鸟四级) | 2015-04-21 13:56

找到错了,妈蛋,我把location.reload()写到ajax外边就不行,得写到success里

支持(0) 反对(0) 吃俺老孙一棒 | 园豆:38 (初学一级) | 2015-04-23 11:07
0

请用vs 调试 ,firebug是调试JS的,另楼上说到点上了

收获园豆:2
zhibudao | 园豆:525 (小虾三级) | 2015-04-21 14:12
0

我碰到这种问题一般是先F12看看http请求的错误原因

收获园豆:2
上位者的怜悯 | 园豆:172 (初学一级) | 2015-04-21 15:10
0

dataType:"JSON" 数据类型加上看看

收获园豆:3
大梦初醒 | 园豆:217 (菜鸟二级) | 2015-04-22 10:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册