开发者

Custom headers with $.ajax type jsnop or json

I have a problem with sending some custom headers to with a jQuery ajax JSON (or JSONP) request.

Code looks like this:

$.ajax({
      beforeSend: function(xhr) {
        xhr.setRequestHeader("X-VER",       VER);
        xhr.setRequestHeader("X-TIMESTAMP", now);
     },
     type: 'GET',
     data: nu开发者_运维问答ll,
     url: site_uri,
     dataType: 'jsonp',
     success: function(msg){$(selector).html(msg);}
});

Firebug shows no custom headers. In addition the url changes with jsonp (can I change this?)

Edit:

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

Thanks for any help


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.


jsonp isn't XHR (you are simply adding script elements to the head), emulating XHR. Hence, you can't set custom headers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜