【问题标题】:Unable to get response text of SOAP request无法获取 SOAP 请求的响应文本
【发布时间】:2012-08-22 13:07:30
【问题描述】:

这是不返回任何内容的代码。我在 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);//肥皂信封

我得到

0Y9eTuEvlrTM55pbRB1kIj0As0bVvz3eFm+p1FY+svHk= en1GBR2012-08-23TO00:00:00.000Z2012-08-24TO00:00:00.000Z

即必填字段之间的数据集

这样可以吗,还是必须有更好的方法来做到这一点?

【问题讨论】:

  • 你的代码的哪一部分没有达到预期的效果?
  • 你的javascript是否在同一个域下运行?
  • 请记住,Ajax 是异步的。
  • 你的 AsynchronousXmlHttpRequest 是 异步的 - 你知道那是什么意思吗?
  • @jbabey 不,它不在同一个域中

标签: javascript soap


【解决方案1】:

正如我在评论中提到的 Ajax 是异步的,因此在您的 js 中您必须执行以下操作:

getmarket.onreadystatechange = function (){
    if (getmarket.readyState == 4 && getmarket.status == 200)
         document.write(getmarket.responseText);
}

onreadystatechange 事件在每次 readyState 改变时触发。

【讨论】:

  • 这行得通吗?因为我已经添加了上面的 sn-p,但我仍然一无所获。请在我发布的网址上给我建议。对吗?
  • @user1511443 我看到你使用 post 方法所以你必须设置标题:getmarket.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  • 我仍然没有得到任何回应。你帮了很多忙。谢谢你。请让我摆脱这个
  • @user1511443 在if 之前添加alert("State = " + getmarket.readyState + " Status = " + getmarket.status);。看看你的要求是否一切正常。
  • 状态=1 和状态=0。有什么问题?
猜你喜欢
  • 1970-01-01
  • 2015-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多