Sha*_*ngh 13 jquery web-services
我需要做跨域Ajax请求 - 这是我的代码
$.ajax(
{
url: redirectURL,
data: $('#login-container form').serialize() + querystring,
type: 'post',
cache: false,
dataType: 'jsonp',
jsonp: 'jsonp_callback',
});
Run Code Online (Sandbox Code Playgroud)
Error: [Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "http://testsite/assets/scripts/jquery-1.3.2.js Line: 19"]
Source File: http://testsite/assets/scripts/jquery-1.3.2.js
Line: 19
Run Code Online (Sandbox Code Playgroud)
我也检查了以下链接 -
$.ajax(
{
url: redirectURL+'?callback=?',
data: $('#login-container form').serialize() + querystring,
type: 'post',
cache: false,
dataType: 'html' });
Run Code Online (Sandbox Code Playgroud)
我也尝试过回调网址.我已经在stackoverflow中看到了关于这个问题的所有链接..但是无法克服这个问题任何人都可以帮助并告诉我如何克服!! 谢谢
Shi*_*ura 30
您将无法在浏览器中执行跨域POST请求.
如果要进行JSONP调用以访问跨域URL,则可以使用JQuery的getJSON方法.这将允许您仅发出GET请求.如果您可以使用GET参数将登录信息提交到redirectURL,则可以使其工作.
请注意,POST到远程登录表单可能是浏览器不允许这样的跨域请求的最佳示例.您不希望看起来像您的银行的网页能够实际为您的银行网站提供数据 - 这将成为非常有效的网上诱骗网页.
另一方面,如果您真的想解决这个问题,可以编写一些服务器端代码,在给定输入参数的情况下,向redirectURL发出post请求并汇总响应.
请告诉我你没有写一个网页仿冒页面.
一种方法是使用您的服务器作为代理:
AJAX Request -> Your server -> Server of interest
AJAX Response Handler <- Your server <- Server of interest
Run Code Online (Sandbox Code Playgroud)