HTTP-POST XHR不能在chrome中工作 [英] HTTP-POST XHR not working in chrome

查看:181
本文介绍了HTTP-POST XHR不能在chrome中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Web应用程序,其中我需要调用服务器cgi,这反过来会使用这些数据进一步使用。
这是我的代码:

I am working on a Web App in which I need to call to the server cgi which will in turn use this data for further use. It working fine in IE6+ and FF but not in chrome 15.(not yet checked with IE6) Here is my code :

 var destinationURL = "/cgi-bin/conf.cgi";
 var xmlHttpReq = getXMLHttpRequest();
    if(xmlHttpReq == null){
        return false;
    } 
    if (xmlHttpReq.readyState == 0){
        xmlHttpReq.open('POST', destinationURL, true);
        xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlHttpReq.onreadystatechange = function() {            
            if (xmlHttpReq.readyState == 4) {              
                alert(xmlHttpReq.responseText);                
            }
        }
        xmlHttpReq.send();                
    } 

getXMLHttpRequest()函数是:

And getXMLHttpRequest() function is :

function getXMLHttpRequest() {
    var xmlHttpReq;
    if (window.XMLHttpRequest) {
        xmlHttpReq = new window.XMLHttpRequest();
    }
    else {
        try {
            xmlHttpReq = new window.ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(ex) {
            alert('Exception in initializing the XMLHttpRequest object '+ex.toString());
            return null;
        }
    }
    return xmlHttpReq;
}

任何解决方案?
提前感谢...

Any solutions ? Thanks in advance...

推荐答案

我将在getXMLHttpRequest()方法中使用以下代码:

I will use the following code in getXMLHttpRequest() method:

var xmlhttp;
if(navigator.appName == "Microsoft Internet Explorer") {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
} else {
    xmlhttp = new XMLHttpRequest();
}

尝试一下,让我们知道

这篇关于HTTP-POST XHR不能在chrome中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆