如何用JQuery实现FLXHR进行跨域交互
我使用JQuery、FLXHR从跨浏览器获取数据 下面是示例jquery代码:如何用JQuery实现FLXHR进行跨域交互,jquery,Jquery,我使用JQuery、FLXHR从跨浏览器获取数据 下面是示例jquery代码: // set up the domain that we're going to call and tell flXHR not to try to parse the response as XML.. $.flXHRproxy.registerOptions("http://staging/", {xmlResponseText:false}); // set flXHR as the de
// set up the domain that we're going to call and tell flXHR not to try to parse the response as XML..
$.flXHRproxy.registerOptions("http://staging/", {xmlResponseText:false});
// set flXHR as the default XHR object used in jQuery AJAX requests
$.ajaxSetup({transport:'flXHRproxy'});
$.ajax({
type:"POST",
url: "http://staging/Login.aspx", // Send the login info to this page
data: str,
dataType: "json",
success: function(result)
{
// Show 'Submit' Button
$('#loginButton').show();
// Hide Gif Spinning Rotator
$('#ajaxloading').hide();
}
});
var ajaxGatewayUrl = "https://staging/login/login.aspx";
var loadPolicyURL = "https://staging/crossdomain.xml"
// set flXHR as the default XHR object used in jQuery AJAX requests
$.ajaxSetup({transport:'flXHRproxy'});
// set up the domain that we're going to call and tell flXHR not to try to parse the response as XML..
$.flXHRproxy.registerOptions(ajaxGatewayUrl,{xmlResponseText:false,loadPolicyURL:loadPolicyURL});
//Submitting the form
$("#loginDetails > form").submit(function()
{
//Hiding the Login button
$("#loginButton").hide();
//Showing the ajax loading image
$("#ajaxloading").show();
// 'this' refers to the current submitted form
var str = $(this).serialize();
// -- Start AJAX Call --
$.ajax({
type:"POST",
url: ajaxGatewayUrl, // Send the login info to this page
data:str,
cache:false,
dataType: "json",
success: function(result)
{
// Show 'Submit' Button
$('#loginButton').show();
// Hide Gif Spinning Rotator
$('#ajaxloading').hide();
if(result.Response!='NULL')
{
$('.validateTips').hide();
var login_response = '<div id="logged_in">' +
'<div style="width: 350px; float: left; margin-left: 80px;">' +
'<div style="width: 40px; float: left;">' +
'<img style="margin: 22px 0px 10px 0px;" align="absmiddle" src="system/images/ajax-loader.gif">' +
'</div>' +
'<div style="margin: 24px 0px 0px 10px; float: right; width: 300px;">'+
"You are successfully logged in! <br /> Please wait while you're redirected...</div></div>";
$('#loginButton').hide();
$('#closeBtn').hide();
$('#divMember').text(result.FirstName +' '+ result.LastName);
$('#spnSkywardsNo').text(result.ActiveCardNo);
$('#spnTierStatus').text(result.MemberShipTier);
$("#ui-dialog-title-skywardsLogin").text(getDataFromResourceFile('pleaseWait'));
$('#divSuccessLogin').html(login_response);
$('#divSuccessLogin').show();
$('#loginDetails').hide();
// After 3 seconds redirect the
setTimeout(closeDialog, 3000);
}
else// ERROR?
{
var login_response = getDataFromResourceFile('InvalidUsername');
$('.validateTips').html(login_response);
}
},
error:function(request, textStatus, errorThrown)
{
// Show 'Submit' Button
$('#loginButton').show();
// Hide Gif Spinning Rotator
$('#ajaxloading').hide();
$('.validateTips').html("Some Issue with requested URL");
}
});
// -- End AJAX Call --
return false;
});
在上面的代码中,我使用JQuery和Flash进行跨浏览器交互,上面的代码运行良好,具有http://staging/Login.aspx,但是当我要选择https://staging/Login.aspx(HTTPS)身份验证其给我的错误(NS\u错误\u代理\u连接被拒绝)
请建议如何解决这个问题
谢谢。我通过以下代码更改解决了我的问题 我得到了以下文章的帮助 (一) (二) (三) 我们必须从FLXHR网站下载插件,并且必须将“Deploy”文件夹的内容复制到保存所有Javascript的同一位置 下面是crossdomain.xml的示例代码,我们需要将其复制到您网站的根目录中
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-only"/>
<allow-access-from domain="*" secure="false"/>
<allow-http-request-headers-from domain="*" headers="*" secure="false"/>
</cross-domain-policy>
下面是JQuery代码:
// set up the domain that we're going to call and tell flXHR not to try to parse the response as XML..
$.flXHRproxy.registerOptions("http://staging/", {xmlResponseText:false});
// set flXHR as the default XHR object used in jQuery AJAX requests
$.ajaxSetup({transport:'flXHRproxy'});
$.ajax({
type:"POST",
url: "http://staging/Login.aspx", // Send the login info to this page
data: str,
dataType: "json",
success: function(result)
{
// Show 'Submit' Button
$('#loginButton').show();
// Hide Gif Spinning Rotator
$('#ajaxloading').hide();
}
});
var ajaxGatewayUrl = "https://staging/login/login.aspx";
var loadPolicyURL = "https://staging/crossdomain.xml"
// set flXHR as the default XHR object used in jQuery AJAX requests
$.ajaxSetup({transport:'flXHRproxy'});
// set up the domain that we're going to call and tell flXHR not to try to parse the response as XML..
$.flXHRproxy.registerOptions(ajaxGatewayUrl,{xmlResponseText:false,loadPolicyURL:loadPolicyURL});
//Submitting the form
$("#loginDetails > form").submit(function()
{
//Hiding the Login button
$("#loginButton").hide();
//Showing the ajax loading image
$("#ajaxloading").show();
// 'this' refers to the current submitted form
var str = $(this).serialize();
// -- Start AJAX Call --
$.ajax({
type:"POST",
url: ajaxGatewayUrl, // Send the login info to this page
data:str,
cache:false,
dataType: "json",
success: function(result)
{
// Show 'Submit' Button
$('#loginButton').show();
// Hide Gif Spinning Rotator
$('#ajaxloading').hide();
if(result.Response!='NULL')
{
$('.validateTips').hide();
var login_response = '<div id="logged_in">' +
'<div style="width: 350px; float: left; margin-left: 80px;">' +
'<div style="width: 40px; float: left;">' +
'<img style="margin: 22px 0px 10px 0px;" align="absmiddle" src="system/images/ajax-loader.gif">' +
'</div>' +
'<div style="margin: 24px 0px 0px 10px; float: right; width: 300px;">'+
"You are successfully logged in! <br /> Please wait while you're redirected...</div></div>";
$('#loginButton').hide();
$('#closeBtn').hide();
$('#divMember').text(result.FirstName +' '+ result.LastName);
$('#spnSkywardsNo').text(result.ActiveCardNo);
$('#spnTierStatus').text(result.MemberShipTier);
$("#ui-dialog-title-skywardsLogin").text(getDataFromResourceFile('pleaseWait'));
$('#divSuccessLogin').html(login_response);
$('#divSuccessLogin').show();
$('#loginDetails').hide();
// After 3 seconds redirect the
setTimeout(closeDialog, 3000);
}
else// ERROR?
{
var login_response = getDataFromResourceFile('InvalidUsername');
$('.validateTips').html(login_response);
}
},
error:function(request, textStatus, errorThrown)
{
// Show 'Submit' Button
$('#loginButton').show();
// Hide Gif Spinning Rotator
$('#ajaxloading').hide();
$('.validateTips').html("Some Issue with requested URL");
}
});
// -- End AJAX Call --
return false;
});
var ajaxGatewayUrl=”https://staging/login/login.aspx";
var loadPolicyURL=”https://staging/crossdomain.xml"
//将flXHR设置为jqueryajax请求中使用的默认XHR对象
$.ajaxSetup({transport:'flXHRproxy'});
//设置我们要调用的域,并告诉flXHR不要尝试将响应解析为XML。。
$.flXHRproxy.registerOptions(ajaxGatewayUrl,{xmlResponseText:false,loadPolicyURL:loadPolicyURL});
//提交表格
$(“#loginDetails>form”).submit(函数()
{
//隐藏登录按钮
$(“#登录按钮”).hide();
//显示ajax加载图像
$(“#ajaxloading”).show();
//“此”是指当前提交的表单
var str=$(this.serialize();
//--启动AJAX调用--
$.ajax({
类型:“POST”,
url:ajaxGatewayUrl,//将登录信息发送到此页面
数据:str,
cache:false,
数据类型:“json”,
成功:功能(结果)
{
//显示“提交”按钮
$(“#登录按钮”).show();
//旋转转子
$('#ajaxloading').hide();
if(result.Response!=“NULL”)
{
$('.validateips').hide();
var login_response=''+
'' +
'' +
'' +
'' +
''+
“您已成功登录!
正在重定向,请稍候…”;
$(“#登录按钮”).hide();
$('#closeBtn').hide();
$('#divMember').text(result.FirstName+''+result.LastName);
$('#spnSkywardsNo').text(result.ActiveCardNo);
$('#spnTierStatus').text(result.MemberShipTier);
$(“#ui对话框标题skywardsLogin”).text(getDataFromResourceFile('pleaseWait');
$('divSuccessLogin').html(登录响应);
$('#divSuccessLogin').show();
$('#loginDetails').hide();
//3秒钟后,重定向
设置超时(closeDialog,3000);
}
还有什么错误?
{
var login_response=getDataFromResourceFile('InvalidUsername');
$('.validateips').html(登录响应);
}
},
错误:函数(请求、文本状态、错误抛出)
{
//显示“提交”按钮
$(“#登录按钮”).show();
//旋转转子
$('#ajaxloading').hide();
$('.validateips').html(“请求的URL存在一些问题”);
}
});
//--结束AJAX调用--
返回false;
});
请查看上面的实现,并提出良好的输入建议。我也可以这样做,但没有明确指定在何处查找crossdomain.xml(它在根目录中自己找到了它)-您是否在没有明确指定在何处查找此文件的情况下进行了测试?