$ .ajax类型的jsnop或json的自定义标头 [英] Custom headers with $.ajax type jsnop or json
问题描述
我在通过jQuery ajax JSON(或JSONP)请求发送一些自定义标头时遇到问题.
I have a problem with sending some custom headers to with a jQuery ajax JSON (or JSONP) request.
代码如下:
$.ajax({
beforeSend: function(xhr) {
xhr.setRequestHeader("X-VER", VER);
xhr.setRequestHeader("X-TIMESTAMP", now);
},
type: 'GET',
data: null,
url: site_uri,
dataType: 'jsonp',
success: function(msg){$(selector).html(msg);}
});
Firebug不显示自定义标头.另外,网址会随着jsonp一起更改(我可以更改吗?)
Firebug shows no custom headers. In addition the url changes with jsonp (can I change this?)
我发现它可能违反了 http://en.wikipedia.org/wiki/Same_origin_policy,但不知道如何解决(脚本不能在同一域中).
I found that it probably violates http://en.wikipedia.org/wiki/Same_origin_policy but have no idea how to get it fixed (the script can't be on the same domain).
感谢您的帮助
推荐答案
If you have server access, a solution would be HTTP access control modification. Otherwise, probably the best idea is some kind of reverse proxy solution, I have no idea how good of support access control has outside of Firefox.
这篇关于$ .ajax类型的jsnop或json的自定义标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!