سؤال

This is (hopefully) an easy question. I have to submit a request to a web service via POST with XDomainRequest. I have found sparse documentation for this across the internet, but I refuse to believe that nobody has figured this out.

Here is my XDomainRequest code:

var testURL = 'http://localhost:4989/testendpoint';

//let us check to see if the browser is ie.  If it is not, let's 
if ($.browser.msie && window.XDomainRequest) {
    var xdr2 = new XDomainRequest();
    xdr2.open("POST", testURL);
    xdr2.timeout = 5000;
    xdr2.onerror = function () {
        alert('we had an error!');
    }
    xdr2.onprogress = function () { 
        alert('we have some progress!');
    };
    xdr2.onload = function () {
        alert('we load the xdr!');

        var xml2 = new ActiveXObject("Microsoft.XMLDOM");
        xml2.async = true;
        xml2.loadXML(xdr2.responseText);
    };

    //what form should my request take to be sending a string for a POST request?  
    xdr2.send("thisisastring");
}

My web service (WCF) takes a single parameter according to the web service's help page, that looks like this:

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">String content</string>

I've gotten this to work via other http clients (mobile and desktop APIs, fiddler) by building a string that concatenates the parameter I am trying to pass to the web service with the rest of the string serialization. For example, I have tried:

xdr2.send("thisisastring");
xdr2.send("<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">thisisastring</string>");

but the onerror handler is always tripped. I don't think it has anything to do with the WCF because:

  • The WCF is always successful in every other client I call it from, and
  • If it was the service, the onerror method would never get tripped. It would return garbage, but it would be returning something.

When i use the console (in the dev tools in ie9) to log the responseText, it says:

LOG:undefined

So I am fairly sure that the issue is in how I use the XDomainRequest.

هل كانت مفيدة؟

المحلول

If anybody comes across this, I ended up converting my web services to return JSON-formatted data. Using JSON negates the need for XDomainRequest, allowing me to use the conventional ajax jquery tools instead.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top