xmlhttp.responseText 空出错
var xmlhttp;
try{
xmlhttp=new XMLHttpRequest();
}catch(e){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
//打开连接,true表示异步提交
xmlhttp.open("post", "ajax_careerwill.asp", true);
//当方法为post时需要如下设置http头
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
//发送数据
xmlhttp.send("d_id="+escape(nl_ve_id)+"&d_ganwei="+escape(nl_ve_gw)+"&d_diqu="+escape(nl_ve_dq)+"&d_zhuf="+escape(nl_ve_zf)+"&d_jobtype="+escape(nl_ve_lx)+"&d_yuexin="+escape(nl_ve_yx)+"&d_beizhu="+escape(nl_ve_bz))
var x=unescape(xmlhttp.responseText);
[b]问题补充:[/b]
加了是不出错,但是
alert()没有出来
[b]问题补充:[/b]
先用提交表单测试过了,服务肯定有返回值,这得不到.
//创建XMLHttpRequest对象
var xmlhttp;
try{
xmlhttp=new XMLHttpRequest();
}catch(e){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
//打开连接,true表示异步提交
xmlhttp.open("post", "ajax_careerwill.asp", true);
//当方法为post时需要如下设置http头
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
//发送数据
xmlhttp.send("d_id="+escape(nl_ve_id)+"&d_ganwei="+escape(nl_ve_gw)+"&d_diqu="+escape(nl_ve_dq)+"&d_zhuf="+escape(nl_ve_zf)+"&d_jobtype="+escape(nl_ve_lx)+"&d_yuexin="+escape(nl_ve_yx)+"&d_beizhu="+escape(nl_ve_bz))
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.write(xmlhttp.responseText);
}
[b]问题补充:[/b]
加了http_request.onreadystatechange = alertContents;
出错
asp处页面是输入出一个id,没有问题.
不明白
谢谢
有莫子不明白的. 好好研究下我给你的第一个帖子吧.
手写AJax就那么几步,踩着步子走就OK了.
如果想好好学习下,有本书<>,很好的.
希望LZ有进步. :idea:
LZ的基本调用过程都是有问题的,请LZ参考这里.
[quote]AJAX基础教程
http://www.iwms.net/n1690c55.aspx[/quote]
[code="java"] http_request.onreadystatechange = alertContents; //设置回调不能少[/code]
[code="java"]
//判断请求是否完成,这个也不能少
if (http_request.readyState == 4) {
if (http_request.status == 200) {
alert(http_request.responseText);
} else {
alert('There was a problem with the request.');
}
}[/code]
如果请求没完成,你就访问responseText,自然是空的.
望有用!
确认一下你的程序返回.
servlet 或者 action 是否返回了信息
:D LZ再自己检查下,没出来,你返回了吗? 你返回的内容,有值吗? :? 怎么才会出来哦.
总的自己分析下,再问问题的号.
LZ怎么不设置回调啊?
[code="java"] 1. http_request.onreadystatechange = alertContents; //设置回调不能少 [/code]
这个加上.
[code="java"]if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.write(xmlhttp.responseText);
} [/code]
写到回调函数里面.
试试看会不会执行到这里. document.write(xmlhttp.responseText);
try it , good luck !