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 :
Any idea ?? One day lost with this problem :(
EDIT: In the Network tab, I have "Failed to load response data".