开发者

Cross domain issue XMLHttp

I face the common cross domain issue with xmlhttp.

I am trying to access WSDL web service using the SOAP protocol. I am not using php and so I can not use the

header('Access-Control-Allow-Origin: *');

I also can't use JSONP as the response I get is not in JSON format but in XML format. Is there any other way that I can resolve this issue.

Here is my code snippet.

var user1="user_name";
var pass1="******";
var url="http://ideone.com/api/1/service.wsdl";

var soap_msg="<?xml version='1.0' encoding='UTF-8' standalone='no'?>"+
"<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'"+          
"xmlns:tns='ht开发者_如何学Gotp://ideone.com:80/api/1/service'    xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'"+
"xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'"+
"xmlns:soap-enc='http://schemas.xmlsoap.org/soap/encoding/' "+
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >"+
"<SOAP-ENV:Body><mns:getLanguages xmlns:mns='http://ideone.com:80/api/1/service' SOAP-  ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>"+
"<user xsi:type='xsd:string'>"+user1 +"</user><pass xsi:type='xsd:string'>"+pass1+"</pass>"+    
"</mns:getLanguages></SOAP-ENV:Body></SOAP-ENV:Envelope>";
var oXmlHttp=  new XMLHttpRequest();
oXmlHttp.open("POST",url,true);
oXmlHttp.setRequestHeader("Content-Type", "text/xml");
oXmlHttp.setRequestHeader("SOAPAction", "http://ideone.com/api/1/service#getLanguages");
oXmlHttp.setRequestHeader("Access-Control-Allow-Origin", "*");
oXmlHttp.send(soap_msg);
var res=oXmlHttp.responseXML;

Thanks in advance.


Here's a link from YUI that you will probably find useful.

http://developer.yahoo.com/yql/guide/yql-jsonp-x.html

They've written a callback which is essentially an envelope that allows for XML to be returned.


Just for the record, Allow Access headers should be set on the server side, that is, on ideone.com which you don't control. At that point, all you can do is along the lines of easyXDM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜