jQuery Call to WebService returns “No Transport” error

前端 未结 8 1598
渐次进展
渐次进展 2020-11-22 15:19

I have the following web service;

    [WebMethod]
    public string HelloWorld()
    {
        return \"Hello World\";
    }

It\'s stock st

8条回答
  •  渐次进展
    2020-11-22 15:46

    I too got this problem and all solutions given above either failed or were not applicable due to client webservice restrictions.

    For this, I added an iframe in my page which resided in the client;s server. So when we post our data to the iframe and the iframe then posts it to the webservice. Hence the cross-domain referencing is eliminated.

    We added a 2-way origin check to confirm only authorized page posts data to and from the iframe.

    Hope it helps

    
    
    //send data to iframe
    var hiddenFrame = document.getElementById('receiver').contentWindow;
    hiddenFrame.postMessage(JSON.stringify(message), 'https://client-server-url');
    
    //The iframe receives the data using the code:
    window.onload = function () {
        var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
        var eventer = window[eventMethod];
        var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
        eventer(messageEvent, function (e) {
            var origin = e.origin;
            //if origin not in pre-defined list, break and return
            var messageFromParent = JSON.parse(e.data);
            var json = messageFromParent.data;
    
            //send json to web service using AJAX   
            //return the response back to source
            e.source.postMessage(JSON.stringify(aJAXResponse), e.origin);
        }, false);
    }
    

提交回复
热议问题