如何添加自定义页眉中的Ajax请求的跨域JSONP调用 [英] How To Add Custom Header in Ajax Request for cross domain JsonP call

查看:155
本文介绍了如何添加自定义页眉中的Ajax请求的跨域JSONP调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何一个可以告诉我如何使用Ajax调用jQuery中添加自定义头跨域JSONP call.i正在使用AJAX跨域call.for即使用JSONP调用Web服务在HTML页面,现在我要送一些参数在头让我怎么设置标题。

Can any one tell me how to add custom header using ajax call in jquery for cross domain jsonp call.i am calling webservice in html page using ajax cross domain call.for that is use jsonp and now i have to send some parameter in header so how i set header.

推荐答案

恐怕,这是不可能的。 jQuery使用一个<脚本> 标签JSONP如你所知,你不能设置自定义页眉与此标记。作为一种可能的解决方法,你可以写上你的域中的服务器端脚本,这将作为您的域和远程域之间的桥梁。然后发送一个正常的AJAX请求到脚本这反过来将委托调用实际的Web服务。既然是服务器到服务器通信的脚本可以设置任何所要求的远程服务HTTP请求头。

I am afraid that this is not possible. jQuery uses a <script> tag for JSONP and as you know, you cannot set custom headers with this tag. As a possible workaround you could write a server side script on your domain which will act as a bridge between your domain and the remote domain. Then send a normal AJAX request to your script which in turn will delegate the call to the actual web service. Since it is a server-to-server communication your script could set any HTTP request headers that are required by the remote service.

这篇关于如何添加自定义页眉中的Ajax请求的跨域JSONP调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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