首页 新闻 会员 周边

AJAX使用Post请求的问题

0
[已解决问题] 解决于 2012-09-04 18:05

使用Post发送请求时,在一般处理程序中无法接收到参数值,但是换成Get请求就可以了,不明白为什么,求指点......

轻狂の书生的主页 轻狂の书生 | 小虾三级 | 园豆:1042
提问于:2012-09-04 16:14
< >
分享
最佳答案
0

你的代码是怎么写的?

奖励园豆:5
artwl | 专家六级 |园豆:16736 | 2012-09-04 16:39
function DoDel(TClassId) {
           // xhr.open("post", "Common.ashx", true);
            xhr.open("get", "Common.ashx?t=d&TClassId=" + TClassId, true);
            xhr.setRequestHeader("Content-Type", "appliaction/x-www-form-urlencoded");
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        var resDel = xhr.responseText;
                        if (resDel == "ok") {
                            DelRow(TClassId);
                        }
                        if (resDel == "nook") {
                            alert("失败");
                        }
                    }
                }
            }
            //xhr.send("t=d&TClassId=" + TClassId);
            xhr.send(null);
        }


代码如图

轻狂の书生 | 园豆:1042 (小虾三级) | 2012-09-04 16:46

@轻狂の书生: 狂汗啊,测试了半个小时,最后发现是你单词写错了,你把

"application"写成了"appliaction",你改过来后用POST方式提交就OK了

artwl | 园豆:16736 (专家六级) | 2012-09-04 17:36

@artwl: 额...

轻狂の书生 | 园豆:1042 (小虾三级) | 2012-09-04 18:04
其他回答(2)
0

开个游览器开发工具,看看你的post请求,是什么样子的?

chenping2008 | 园豆:9836 (大侠五级) | 2012-09-04 16:55
0
"Content-Type", "application/x-www-form-urlencoded"  post必须有的头
喵喵喵猫 | 园豆:1742 (小虾三级) | 2012-09-04 17:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册