Ajax request from local file

假装没事ソ 提交于 2019-12-25 07:06:53

问题


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()



来源:https://stackoverflow.com/questions/26822535/ajax-request-from-local-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!