请各位能帮我一下,刚学ajax,什么都不懂.下面程序为什么不能获取到值?
function Button2_onclick() {
var name=document.getElementById("u_name").value;
XmlHttpRequest=new ActiveXObject("Msxml2.XMLHTTP");
XmlHttpRequest.open("POST","IsHave.ashx",true);//IsHava.ashx用来验证的
XmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
XmlHttpRequest.send(name);
XmlHttpRequest.onreadystatechange=response_data;
}
function response_data()
{
if(XmlHttpRequest.readyState==4)
{
if(XmlHttpRequest.status==200)
{
alert(XmlHttpRequest.responseText);//什么都没显示
}
}
}
public class IsHave : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
String[] kk=context.Request.Form.AllKeys;
if (kk.Length >0)
{
string name=kk[0];//改为name=context.Request.Form.GetKey(0);也不行
//明明检查到kk的长度为1,但是就是不能把kk[0]附值给name;
if (name.length>0)//这里开始就没执行了,为什么会这样?
context.Response.Write(name+"yes");
}
}
function Button2_onclick() {
var name=document.getElementById("u_name").value;
XmlHttpRequest=new ActiveXObject("Msxml2.XMLHTTP");
XmlHttpRequest.open("POST","IsHave.ashx",true);//IsHava.ashx用来验证的
XmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
XmlHttpRequest.send(name);
XmlHttpRequest.onreadystatechange=response_data;
}
function response_data()
{
if(XmlHttpRequest.readyState==4)
{
if(XmlHttpRequest.status==200)
{
alert(XmlHttpRequest.responseText);//什么都没显示
}
}
}
public class IsHave : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
String[] kk=context.Request.Form.AllKeys;
if (kk.Length >0)
{
string name=kk[0];//改为name=context.Request.Form.GetKey(0);也不行
//明明检查到kk的长度为1,但是就是不能把kk[0]附值给name;
if (name.length>0)//这里开始就没执行了,为什么会这样?
context.Response.Write(name+"yes");
}
}
或者
kk[0].value试验一下===================================================
技术交流不该有界限 资源共享不该有条件
博客空间:http://blog.csdn.net/lovingkiss
资源下载:http://download.csdn.net/user/lovingkiss
Email:loving-kiss@163.com
本人说明:<我的帖子我做主,结贴率保持100%>
1、欢迎一切问题有关的交流——无论答案对错;
2、不欢迎 顶、Mark、支持之类口水混分的人;
3、对带有性别的主题和求全部毕业代码者尽量不回答;
我保留对非<散分贴>蹭分者的厌恶和鄙视...
精通:jīnɡtōnɡ对学问技术等透彻的了解并熟练掌握
所以,我没有精通,只有JZ
===================================================
改成:
var name="key="+document.getElementById("u_name").value; public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
String[] kk=context.Request.Form.AllKeys;
if (kk.Length >0)
{
string name=kk[0];//改为name=context.Request.Form.GetKey(0);也不行
//明明检查到kk的长度为1,但是就是不能把kk[0]附值给name;
if (name.length>0)//这里开始就没执行了,为什么会这样?
context.Response.Write(name+"yes");
}
}改成:
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string name=context.Response.Form["key"];
if (name.length>0)//这里开始就没执行了,为什么会这样?
context.Response.Write(name+"yes");
}
技术交流不该有界限 资源共享不该有条件
博客空间:http://blog.csdn.net/lovingkiss
资源下载:http://download.csdn.net/user/lovingkiss
Email:loving-kiss@163.com
本人说明:<我的帖子我做主,结贴率保持100%>
1、欢迎一切问题有关的交流——无论答案对错;
2、不欢迎 顶、Mark、支持之类口水混分的人;
3、对带有性别的主题和求全部毕业代码者尽量不回答;
我保留对非<散分贴>蹭分者的厌恶和鄙视...
精通:jīnɡtōnɡ对学问技术等透彻的了解并熟练掌握
所以,我没有精通,只有JZ
===================================================
改成:
var name="key="+document.getElementById("u_name").value; public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
String[] kk=context.Request.Form.AllKeys;
if (kk.Length >0)
{
string name=kk[0];//改为name=context.Request.Form.GetKey(0);也不行
//明明检查到kk的长度为1,但是就是不能把kk[0]附值给name;
if (name.length>0)//这里开始就没执行了,为什么会这样?
context.Response.Write(name+"yes");
}
}改成:
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string name=context.Response.Form["key"];
if (name.length>0)//这里开始就没执行了,为什么会这样?
context.Response.Write(name+"yes");
}
嘿嘿 借用 wzd24(牧野)(衣带渐宽终不悔,为伊消得人憔悴) ( )
回lovingkiss(桃花影落飞神贱,碧海潮生<吹>玉箫 坦白从良 抗拒强奸)
context.Request.Form.GetKey(0).value是没有value属性的.不过你的建议"进行断点跟踪——找到kk[0],看看它是什么类型,都有什么属性,每个属性的值是什么
"启发了我.
谢谢 wzd24(牧野)(衣带渐宽终不悔,为伊消得人憔悴) 大侠了.