weixin_33744854 2015-01-10 20:49 采纳率: 0%
浏览 15

AJAX响应始终为空

I have a problem to get the answer of an XMLHttpRequest.

Here is my code :

function PYX_SendCommand(szCommand, szContent) {
    PYX_Client = 'http://127.0.0.1/Pyxvital.exe/soap/IPyxvital';

    // CONSTRUCT DATA
    str_content = '' + '<?xml version="1.0"?>';
    str_content = str_content + '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">';
    str_content = str_content + '<SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">';
    if (szContent != null) {
        str_content = str_content + '<NS1:SSV_Write xmlns:NS1="urn:Pyxvital-IPyxvital">';
        str_content = str_content + '<szFlux xsi:type="xsd:string">' + szCommand + '</szFlux>';
        str_content = str_content + '<szContent xsi:type="xsd:string">' + szContent + '</szContent>';
        str_content = str_content + '</NS1:SSV_Write>';
    } else if (szCommand.substr(szCommand.length - 4, 4) == '.par') {
        str_content = str_content + '<NS1:SSV_Read xmlns:NS1="urn:Pyxvital-IPyxvital">';
        str_content = str_content + '<szFlux xsi:type="xsd:string">' + szCommand + '</szFlux>';
        str_content = str_content + '</NS1:SSV_Read>';
    } else {
        str_content = str_content + '<NS1:SSV_Command xmlns:NS1="urn:Pyxvital-IPyxvital">';
        str_content = str_content + '<cmdShow xsi:type="xsd:int">1</cmdShow>';
        str_content = str_content + '<szCommand xsi:type="xsd:string">' + szCommand + '</szCommand>';
        str_content = str_content + '</NS1:SSV_Command>';
    }
    str_content = str_content + '</SOAP-ENV:Body>';
    str_content = str_content + '</SOAP-ENV:Envelope>';


    // SEND DATA
    xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if ((xhr.readyState == 4) && (xhr.status == 200)) {
            alert(xhr.responseText);
        }
    };
    xhr.open("POST", PYX_Client, true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.send(str_content);

}

The problem is that the condition (xhr.readyState == 4) && (xhr.status == 200) is never true. When I have xhr.readyState = 4, xhr.status equals to 0 and xhr.responseText is always empty. Very strange because I can see the TCP transactions with WireShark :

enter image description here

Any idea ?? One day lost with this problem :(

EDIT: In the Network tab, I have "Failed to load response data".

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 学不会递归,理解不了汉诺塔参数变化
    • ¥30 软件自定义无线电该怎样使用
    • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
    • ¥15 Jenkins+k8s部署slave节点offline
    • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
    • ¥15 WPF使用Canvas绘制矢量图问题
    • ¥15 用三极管设计一个单管共射放大电路
    • ¥15 孟德尔随机化r语言运行问题
    • ¥15 pyinstaller编译的时候出现No module named 'imp'
    • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)