【问题标题】:Issue with using ajax to call a .php file that redirects user to different page使用 ajax 调用将用户重定向到不同页面的 .php 文件的问题
【发布时间】:2012-12-31 07:57:57
【问题描述】:

大家好,我正在创建一个 TOS 弹出窗口,如果用户拒绝 .ajax 函数,则会调用一个 .php 文件,该文件会破坏他们的会话并将其发送回登录页面。

这是一个受 SSL 锁保护的网站,所以我收到一条错误消息:

where the ajax function is that gets the other page with the destroy session and redirect 的页面显示来自the login page which is suppose to be sent to, the user. 的不安全内容

功能:

function decline(){

 $("#dialog-container").dialog( 'close' );
 /*****run ajax to kill session of current user and return to login page ******/
  $.ajax({ url: 'termsofservice/declinedkill.php',
         data: {},
         type: 'get',
         success: function(output) {
                  }
});
}

这里是被拒绝的kill.php:

session_start();
session_destroy();

header("location:/PCG/mainlogin.php");

我确定我没有使用任何包含其他文件等的链接。所以不确定是什么问题。

谢谢,大卫 :)

编辑:

这是我正在使用的更新链接:

$.ajax({ url: '//mysite.com/PCG/termsofservice/declinedkill.php',
         data: {},
         type: 'post',
         success: function(output) {
                  }
});

declinedkill.php

header("location:https://mysite.com/PCG/mainlogin.php");

所以现在我没有收到该消息,但我没有被重定向?

【问题讨论】:

  • 对不起....我会重新编辑的
  • 不发送重定向怎么样?只需在成功处理程序中设置 window.location ?您可以让 AJAX 调用返回要关注的 URL

标签: java php javascript ajax ssl


【解决方案1】:

如果您的站点使用 SSL,您还需要调用脚本的 SSL URL。

像这样:

function decline(){

 $("#dialog-container").dialog( 'close' );
 /*****run ajax to kill session of current user and return to login page ******/
  $.ajax({ url: '//yoursite.com/termsofservice/declinedkill.php',
         data: {},
         type: 'get',
         success: function(output) {
                  }
});
}

// 代替 https:// 或 http:// 它用于自动选择正确的 URI 方案。 它们被称为相对于协议的 URL。 Check this link 了解更多信息。

【讨论】:

  • 当您使用协议相对 URL 时不需要。再次查看我的帖子。您可以硬编码 https url,但这更好。
  • 在 Location: 和 url 之间使用一个空格。 header("Location: https://mysite.com/PCG/mainlogin.php"); 还要确保在调用标头之前没有输出(如空格)。
  • 我实际上只是在成功部分将其更改为 javascript 重定向!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多