来自本地文件的Ajax请求 [英] Ajax request from local file

查看:127
本文介绍了来自本地文件的Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JQuery.Soap插件在内部执行具有跨域请求的HTA.

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);
    }
});    

它在IE11中完美地工作,但是只有当我在Web服务器上将其作为页面打开时才可以.如果我在PC上将其作为文件打开-与HTA一样,出现错误无传输".可以使用Ajax创建独立页面吗?

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?

推荐答案

由于现代浏览器中的同源策略限制,Ajax本身不支持-但是应该可以通过JSONP加载数据( http://en.wikipedia.org/wiki/JSONP )

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)

它的工作原理是基本上按需添加<script src="">标记,然后使用您的数据加载外部js文件并调用函数,例如dataLoaded()

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

这篇关于来自本地文件的Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆