2013-03-13 161 views
1

重定向由于一些要求,我需要登录到使用jQuery AJAX网站..但是当我尝试这样做.. Firebug控制台是说,它是302错误。 我试图实施其处理,但遗憾的是没有成功故障处理302与jQuery AJAX

下面的代码是我的代码我已经试过至今:

<script type='text/javascript' src='http://code.jquery.com/jquery.js'> 
    </script> 
    <script type='text/javascript'> 


    $(document).ready(function(){ 


    $.ajax({ 

    url  : "https://testDomain/login.asp", 
    async  : false, 
    type  : 'POST', 
    data  : {Username:'test',Password:'testPass'}, 
    success : function(respText){alert(respText);}, 

    error  : function (jqXHR, textStatus, errorThrown) 
       { 
        console.log(jqXHR.getResponseHeader("Location")); // undefined; 
       }, 

    statusCode: { 
       302: function() { 
           alert("page not found"); 
          } 
       },     
    complete : function(response) { 
       if(response.status == 302) { 
        window.alert('page not found');  
       } 
    } 
     }) 

    }); 

    </script> 

当我看到响应头,他们显示为

Date   Wed, 13 Mar 2013 06:43:18 GMT 
Location  https://testDomain/pageXXX.asp 
Server   Microsoft-IIS/6.0 
Set-Cookie  TravAuthV=e;path=/; domain=testDomain.com; 
X-Powered-By ASP.NET 

我在想什么..?或者有没有其他的替代来处理这个

感谢您的时间..任何帮助将不胜感激......

回答

1

你是不是缺少什么问题在下面一行。

url  : "https://testDomain/login.asp", 

您正在使用AJAX发送SSL请求,我不认为它的工作,因为它违反了JavaScript的政策,因为它没有看到来自同一来源要求的非SSL链接的SSL ..

你能做些什么?

您可以从服务器添加Access-Control-Allow-Origin头。

Access-Control-Allow-Origin: https://testDomain/login.asp 

Read More

尝试使用设置crossDomain : truedataType:jsonp如果没有jsonp响应然后将其删除。

$.ajax(
{ 
    url: 'https://testDomain/login.asp', 
    async  : false, 
    type  : 'POST', 
    data  : {Username:'test',Password:'testPass'}, 
    success : function(respText){alert(respText);}, 
    crossDomain: true, 
    dataType: 'jsonp', 
    error: function() { alert('Failed!'); }, 
    beforeSend: function(xhr) 
    { 
     xhr.setRequestHeader('Authorization',getToken()); 
    } 
}); 
+0

你的意思是我不能通过非ssl请求发送ajax请求到ssl域...? – alwaysLearn 2013-03-13 05:58:37

+0

@new_developer看到我的更新答案.. – 2013-03-13 06:07:37

+0

是的,我想它..很快就会更新您 – alwaysLearn 2013-03-13 06:08:29