//发送数据
function AjaxSend(url,name,value){
xmlhttp = createXMLHttpRequestOblect();
xmlhttp.open('get',url,false);
var body=name+"="+value;
var result="";
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
result = unescape(xmlhttp.responseText);
}else{
result=xmlhttp.status;
}
}
}
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.send(body);
return result;
}
我在IE中测试可以获取数据,就是result有结果,但是firefox中result的值依旧是“”,这个是为什么?
function AjaxSend(url,name,value){
xmlhttp = createXMLHttpRequestOblect();
xmlhttp.open('get',url,false);
var body=name+"="+value;
var result="";
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
result = unescape(xmlhttp.responseText);
}else{
result=xmlhttp.status;
}
}
}
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.send(body);
return result;
}
我在IE中测试可以获取数据,就是result有结果,但是firefox中result的值依旧是“”,这个是为什么?
解决方案 »
- 用javascript写了个类,操作异步XMLHTTP的onreadystatechange时怎么取得类this指针
- javascript中如果按钮是灰色的如何才能点击?
- 怎样通过点击按钮复制<span>与</span>之间的内容?
- 看不明白的问题,可能属于js面向对象方面,在ajax里用的
- javascript的'和"可以用什么替代
- 送分,如何使Button变灰(.Enabled=false)?
- js检查日期的问题
- 简单的问题!!!
- 我要在网页中加入一个可以画图(曲线图,柱形图,K线图)的控件,请问各位大虾哪里有? 必给分!
- 固定宽度的瀑布流怎么实现呀?
- JS在HTML中的判断取值问题
- 如何利用正则来提取制定的段落
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
function createXMLHttpRequestOblect()
{
try
{
xmlhttp = new XMLHttpRequest();
}
catch(e)
{
var XMLHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
"MSXML2.XMLHTTP.5.0",
"MSXML2.XMLHTTP.4.0",
"MSXML2.XMLHTTP.3.0",
"MSXML2.XMLHTTP",
"Microsoft.XMLHTTP");
for (var i=0; i < XMLHttpVersions.length && !xmlhttp; i++ )
{
try
{
xmlhttp = new ActiveXObject(XMLHttpVersions[i]);
}
catch (e) {}
}
}
if(!xmlhttp)
alert("Error Creating the XMLHttpRequest Oblect.");
else
return xmlhttp;
}
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
result = unescape(xmlhttp.responseText);
//如果这里加alert(result)结果也是正确的,但是末尾返回的result就是"";
}else{
result=xmlhttp.status;
}
}
创建xmlhttp对象