【问题标题】:jQuery redirect doesn't workjQuery重定向不起作用
【发布时间】:2017-04-16 12:02:24
【问题描述】:

我需要转到另一个页面并发布一些数据。我想从“index.php”发布 Javascript 变量并在“zakazka.php”上获取 PHP 变量。我需要通过单击跨度文本来启动该功能,所以我不想使用表单。

我发现重定向会对我有所帮助,但不能让一个简单的示例工作 -

索引.php:

<html>
 <head>
  <script src="https://code.jquery.com/jquery-2.2.4.js"></script>
 </head>
<body>

<?php
session_start();
$user="abc";
$_SESSION["user"] = $user;
?>

<span id="1" onclick="get()">hello</span>
</body>
</html>

<script>
function get()
  {
  kod="1";
  $.redirect('zakazka.php', {'kodsend': kod});  
  }
</script>

Zakazka.php:

<?php
session_start();
$user=$_SESSION['user'];
$kodr = $_POST['kodsend'];

echo $kodr;
?>

【问题讨论】:

  • “它什么都不做” ...实际上它会在您的浏览器控制台中引发错误。您没有为$.redirect 包含任何定义。你也不能这样发帖……应该是$_GET['kodsend']

标签: jquery redirect


【解决方案1】:

这个方法不是 jQuery 原生的。我假设它是这个插件,虽然你没有提到它:https://github.com/mgalante/jquery.redirect

如果是这样,您需要包含类似

的内容

&lt;script src="path/to/jquery.redirect.js"&gt;&lt;/script&gt;

在您的页面中,确保您将插件文件下载到您网站的正确文件夹中。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-11
  • 1970-01-01
  • 2017-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多