$ .ajax类型的jsnop或json的自定义标头 [英] Custom headers with $.ajax type jsnop or json

查看:71
本文介绍了$ .ajax类型的jsnop或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屋!

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