Ajax request from local file

2019-09-01 05:38发布

问题:

I'm trying to make a HTA with cross-domain request inside using JQuery.Soap plugin.

$.soap({
    url: 'some url',
    method: 'some method',
    appendMethodToURL: false, 
    namespaceURL: 'some namespace',
    enableLoggin: true,
    data: {},
    success: function (response) {
        alert(response);
    },
    error: function (response) {
        alert(response);
    }
});    

It's work perfectly in IE11, but only when I open it as a page on webserver. If I open it as a file on my PC - I get error "No transport", same with HTA. Is it possible to make a standalone page with Ajax?

回答1:

Not with Ajax itself, due to the same-origin policy restriction in modern browsers - what should be possible however is to load data via JSONP (http://en.wikipedia.org/wiki/JSONP)

It works by basically adding a <script src=""> tag on demand, which then loads an external js file with your data and makes a call to a function e.g. dataLoaded()