如何使用JQuery实现FLXHR以进行跨域交互

我正在使用JQuery,FLXHR从Cross Browser获取数据。

下面是示例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(); } }); 

在上面的代码中,我使用JQuery和Flash进行跨浏览器交互,上面的代码工作正常,使用http://staging/Login.aspx ,但是当我要使用https://staging/Login.aspx (HTTPS)时validation它给我错误(NS_ERROR_PROXY_CONNECTION_REFUSED)

请建议如何摆脱这个问题。

谢谢。

我通过以下代码更改解决了我的问题。

我接受了以下文章的帮助。

1) http://www.offshootinc.com/blog/2010/03/12/cross-domain-scripting-with-jquery-and-flxhr/

2) http://tek-insight.blogspot.com/2010/05/cross-domain-ajax-request-proxy-json.html

3) http://flxhr.flensed.com

我们必须从FLXHR网站下载插件,并且必须在保存所有Javascript的同一位置复制“Deploy”文件夹的内容。

下面是我们需要在您网站的根目录中复制的crossdomain.xml示例代码。

        

这里是JQuery代码:

  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 = '
' + '
' + '
' + '' + '
' + '
'+ "You are successfully logged in!
Please wait while you're redirected...
"; $('#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; });

请查看以上实施并建议良好的输入。