gpt4 book ai didi

javascript - JQuery ajax 函数确实有效,但 php 脚本无效

转载 作者:行者123 更新时间:2023-11-30 05:37:57 26 4
gpt4 key购买 nike

好吧,这是我的问题,我有一个 jquery 函数和一个 php 脚本

jquery函数:

function set_session(para){
//Send Ajax request
var dataString = 'waarde='+ para ;
jQuery.ajax({
url: '../js/set_session_side.php',
type: 'POST',
data: dataString,
cache: false,
success: function(data, textStatus, xhr) {
console.log(data); // do with data e.g success message
},
error: function(xhr, textStatus, errorThrown) {
console.log(textStatus.reponseText);
}
});}

set_session.php:

<?php 
$_SESSION['side'] = $_POST['waarde'];
?>

当我运行 jquery 函数时成功,但没有数据,我的 php 脚本不工作/或没有被触发,因为 $_SESSION['side'] 没有改变。

我们将不胜感激任何帮助。提前致谢

最佳答案

  1. 首先确保您的请求脚本是正确的。
  2. 在 set_session.php 的开头添加 sesstion_start()(我相信你的问题就在这里);

关于javascript - JQuery ajax 函数确实有效,但 php 脚本无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22436888/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com