这是不返回任何内容的代码。我在 SOAP UI 中使用了相同的 SOAP 请求,并且得到了正确的响应 只是它没有出现在 javascript 中。
var getmarket = new XMLHttpRequest();
getmarket.open('POST', 'https://www.betfair.com/publicapi/', true);
var m_request = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" '+
'xmlns:bfex="http://www.betfair.com/publicapi/v5/BFExchangeService/" '+
'xmlns:v5="http://www.betfair.com/publicapi/types/exchange/v5/">'+
' <soapenv:Header/>'+
'<soapenv:Body>'+
'<bfex:getAllMarkets>'+
'<bfex:request>'+
'<header>'+
'<clientStamp>0</clientStamp>'+
'<sessionToken>Y9eTuEvlrTM55pbRB1kIj0As0bVvz3eFm+p1FY+svHk=</sessionToken>'+
'</header>'+
'<locale>en</locale>'+
'<eventTypeIds>'+
'<v5:int>1</v5:int>'+
'</eventTypeIds>'+
'<countries>'+
'<v5:Country>GBR</v5:Country>'+
'</countries>'+
'<fromDate>2012-08-23TO00:00:00.000Z</fromDate>'+
'<toDate>2012-08-24TO00:00:00.000Z</toDate>'+
'</bfex:request>'+
'</bfex:getAllMarkets>'+
'</soapenv:Body>'+
'</soapenv:Envelope>';
getmarket.setRequestHeader('Content-Type', 'text/xml');
getmarket.send(m_request);
document.write(getmarket.responseText);
另外当我使用 document.write(m_request);//SOAP 信封
我得到
0Y9eTuEvlrTM55pbRB1kIj0As0bVvz3eFm+p1FY+svHk= en1GBR2012-08-23TO00:00:00.000Z2012-08-24TO00:00:00.000Z
即必填字段之间的数据集
这样可以吗,还是必须有更好的方法?
最佳答案
正如我在评论中提到的,Ajax
是异步的,因此在您的 js
中,您必须执行以下操作:
getmarket.onreadystatechange = function (){
if (getmarket.readyState == 4 && getmarket.status == 200)
document.write(getmarket.responseText);
}
onreadystatechange
事件在每次 readyState 改变时触发。
关于javascript - 无法获取 SOAP 请求的响应文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12073872/