Php 使用jquery ajax处理302重定向时遇到的问题

Php 使用jquery ajax处理302重定向时遇到的问题,php,javascript,ajax,jquery,Php,Javascript,Ajax,Jquery,由于某些要求,我需要使用jquery ajax登录到一个站点。。但是当我试着这么做的时候。。firebug控制台说这是302错误。 我已经尝试实现代码来处理它,但不幸的是没有成功 这是我迄今为止一直尝试的代码: <script type='text/javascript' src='http://code.jquery.com/jquery.js'> </script> <script type='text/javascript'> $(doc

由于某些要求,我需要使用jquery ajax登录到一个站点。。但是当我试着这么做的时候。。firebug控制台说这是302错误。 我已经尝试实现代码来处理它,但不幸的是没有成功

这是我迄今为止一直尝试的代码:

<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>
我错过了什么??或者有其他方法来处理这个问题吗


谢谢你抽出时间。。任何帮助都将不胜感激

您没有遗漏任何问题,问题在下面一行

url        : "https://testDomain/login.asp",
您正在使用ajax发送SSL请求,我认为它不起作用,因为它违反了Javascript的策略,因为它没有看到来自与非SSL url相同来源的SSL请求

你能做什么?

您可以从服务器添加
访问控制允许源站
标题

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

尝试使用设置
crossDomain:true
dataType: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());
    }
});

你们并没有遗漏任何东西,问题在下面

url        : "https://testDomain/login.asp",
您正在使用ajax发送SSL请求,我认为它不起作用,因为它违反了Javascript的策略,因为它没有看到来自与非SSL url相同来源的SSL请求

你能做什么?

您可以从服务器添加
访问控制允许源站
标题

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

尝试使用设置
crossDomain:true
dataType: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());
    }
});

你的意思是我不能通过非ssl请求向ssl域发送ajax请求@新的开发者这是我的错误,你需要通过授权检查函数并创建该函数来检查身份验证。我已经创建了函数getToken(),它将返回“test:testPass”的base 64值。。但是现在ajax没有发送请求..:(对此有进一步的建议吗…?你的意思是我不能通过非ssl请求将ajax请求发送到ssl域…?@new_developer这是我的错误,相反,你需要通过授权检查函数并创建该函数来检查身份验证。我创建了函数getToken(),该函数返回“test:testPass”的基64值…但是现在ajax并没有发送请求……:(对此有进一步的建议吗…?)?