如何解决无法弄清楚如何将信息从一个 .php 文件发送到另一个 .php 文件 first.phpsecond.php
我试图通过 POST 发送一个数组,通过 GET 将 2 个变量从 first.PHP 发送到 second.PHP 文件,但我似乎无法让它工作。 对于所有 3 个,我收到错误消息 Undefined index
<?PHP
session_start();
$_SESSION["trys"] = 0;
echo "<hr/><pre>".print_r($_SESSION,1)."</pre><hr/>";
?>
<script>
//array
arrayIDs = [04,05,45,55]
$.ajax({
url: 'second.PHP',type: 'post',data: {arrayIDs: arrayIDs},success: function(response){
console.log("POST !DELA!")
}
});
//string //x=0&y=9
url = "second.PHP?" + "x=" + x + "&y=" + y;
// I send it through get
</script>
<html>
//some tables data is generated from
</html>
second.PHP
<?PHP
session_start();
$kliknjenX = $_GET["x"];
$kliknjenY = $_GET["y"];
$kliknjenID = $kliknjenX + "" + $kliknjenY;
$arrayIDs = $_POST['arrayIDs'];
?>
解决方法
原因是因为您实际上从未针对请求发送任何 GET
数据...
<script>
//array
arrayIDs = [04,05,45,55]
$.ajax({
url: 'second.php',// <<-- This line doesn't have GET variables
type: 'post',data: {arrayIDs: arrayIDs},success: function(response){
console.log("POST !DELA!")
}
});
url = "second.php?" + "x=" + x + "&y=" + y; // <<-- This line does nothing
</script>
<html>
//some tables data is generated from
</html>
应该是:
<script>
//array
var arrayIDs = [04,55];
var x = "some_url_encoded_value";
var y = "another_encoded_value";
var destination_url = "second.php?x=" + x + "&y=" + y;
$.ajax({
url: destination_url,type: 'post',success: function(response){
console.log("POST !DELA!")
}
});
</script>
<html>
//some tables data is generated from
</html>
,
我认为这将帮助您测试它:
first.php
<?php
session_start();
$_SESSION["trys"] = 0;
echo "<hr/><pre>".print_r($_SESSION,1)."</pre><hr/>";
?>
<script>
arrayIDs = [04,55]
$.ajax({
url: 'second.php?x=0&y=9',success: function(response){
console.log("POST !DELA!")
}
});
</script>
<html>
//some tables data is generated from
</html>
second.php
<?php
session_start();
$kliknjenX = $_GET["x"];
$kliknjenY = $_GET["y"];
$kliknjenID = $kliknjenX + "" + $kliknjenY;
$arrayIDs = $_POST['arrayIDs'];
?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。