繁体   English   中英

在执行JQuery Ajax调用之后,无法从后续的Slim URL重定向请求标头中删除“ X-Requested-With”

[英]After a JQuery Ajax call, unable to remove “X-Requested-With” from subsequent Slim URL redirect request headers

调用JQuery AJAX之后,所有后续的Slim重定向在请求标头中都包含“ X-Requested-With:XMLHttpRequest”。 结果,重定向页面的内容在响应中在后台返回,但是浏览器没有重定向到预期的URL。 不知道我在做什么错。

我的Ajax调用如下所示(这是https://developers.google.com/+/web/signin/server-side-flow的实现):

function signInCallback(authResult) {
    if (authResult['code']) {
        // Hide the sign-in button now 
        $('#signinButton').attr('style', 'display: none');
        // Send the code to the server
        $.ajax({
            type: 'GET',
            url: '../google/',
            contentType: 'application/octet-stream; charset=utf-8',
            success: function(result) {
                console.log(authResult['code']);
            },
            data: "gplustoken="+authResult['access_token'],
            error: function (request, status, error) {
                console.log("Error");
            }
         });
    } else if (authResult['error']) {
         // There was an error.
    }
}

}

PHP Slim URL重定向代码如下:

$app->redirect($app->urlFor("home"));

对于以上内容,请参见: https : //github.com/TheRosettaFoundation/SOLAS-Match/blob/master/ui/RouteHandlers/UserRouteHandler.class.php#L413

我试图从PHP / Slim代码的请求标头中删除“ X-Requested-With”,如下所示,但它也不起作用。

 $isAjaxRequest = $app->request->headers->get('X-Requested-With') == 'XMLHttpRequest';
 if ($isAjaxRequest) {
     if (isset($_SERVER['HTTP_X_REQUESTED_WITH']))
     {
         unset($_SERVER['HTTP_X_REQUESTED_WITH']);
         //$app->request->headers->set('X-Requested-With','');
         $app->redirect($app->urlFor("home"));
     }

  } else
       $app->redirect($app->urlFor("home"));

非常感谢您解决此问题的任何帮助。

查看Http Headers对象的Slim文档,您应该可以通过调用remove方法来实现此目的:

$app->request->headers->remove('X-Requested-With');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM