关于用于重定向的PHP标头,浏览器在下面的情况下中止它 [英] About PHP header for redirection, browser aborts it in below case

查看:71
本文介绍了关于用于重定向的PHP标头,浏览器在下面的情况下中止它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,我们使用ajax调用请求服务(php文件)。其中我有PHP函数从DB读取数据并将其发回,如果在获取数据时出现故障,我会使用标题重定向到错误文件。



在我的本地机器上,即使使用http / https请求,一切正常。但是在与我的本地配置设置完全相同的特定服务器上,它的头部请求是已中止并且重定向失败。



我想知道什么东西可能会导致这种情况。这种行为的 REASON 是什么。

 Ajax Call:
$ .ajax({
url:'getdataForUser。 php',
类型:'POST',
data:{'User':userName
},
dataType:'html',
success:function(data ){
console.log(data);
},
错误:function(){
console.log('call error。');

}
});



PHP函数:getdataForUser.php

<?php 
session_start();
if(isset($ _ POST))
{
$ transaction = array('User'=> $ _POST ['User']
);
}
$ result = $ client-> __ soapCall(GetUserDetails,array($ transaction));
if($ result == FALSE)
{
header('Location:error.php'); //这个重定向被中止了
die();
}
print_r($ result);

?>

解决方案

.ajax({
url:'getdataForUser.php' ,
类型:'POST',
数据:{'用户':userName
},
dataType:'html',
成功:函数(数据){
console.log(data);
},
错误:function(){
console.log('call error。');

}
});



PHP函数:getdataForUser.php

<?php 
session_start();
if(isset(


_POST))
{


transaction = array('User'=>

I have a function, in which we do request to a service(a php file) using ajax call. In which I have PHP function which read data From DB and send that back, in case of failure while getting the data I do redirect using header to the error file.

On my local machine all works fine even with http/https request. But on a specific sever which has all same configuration settings as my local one, it header request is "Aborted" and redirection fails.

I would like to know what things might lead to such situation. What is the REASON of such behaviour.

Ajax Call :
$.ajax({
    url: 'getdataForUser.php',
    type: 'POST',
    data: { 'User' : userName
            },
    dataType: 'html',                         
    success: function (data) {
        console.log(data);                                                      
     },
    error : function() {
        console.log('call error .');

    }
}); 


PHP Function : getdataForUser.php

<?php
    session_start();
    if(isset($_POST))
    {
        $transaction = array('User' => $_POST['User']
                         );
    }
    $result = $client->__soapCall("GetUserDetails",array($transaction));
    if($result == FALSE)
    {
        header( 'Location: error.php' ); // THIS REDIRECTION IS BEING ABORTED
        die();
    }
    print_r($result);

?>

解决方案

.ajax({ url: 'getdataForUser.php', type: 'POST', data: { 'User' : userName }, dataType: 'html', success: function (data) { console.log(data); }, error : function() { console.log('call error .'); } });


PHP Function : getdataForUser.php

<?php
    session_start();
    if(isset(


_POST)) {


transaction = array('User' =>


这篇关于关于用于重定向的PHP标头,浏览器在下面的情况下中止它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆