gpt4 book ai didi

php - 如何将 jquery var 发送到 php?

转载 作者:可可西里 更新时间:2023-11-01 00:23:57 24 4
gpt4 key购买 nike

当我尝试用 jquery 发送一个 var 时,ajax php 没有收到它,我不知道为什么。

这是我的脚本:

function showHiddenUserInfoPanel(id){
$(document).ready(function(){
$('#admin-resume').fadeToggle('slow', 'linear', function(){
$.ajax({
async: true,
type: "POST",
dataType: "html",
contentType: "application/x-www-form-urlencoded",
data: "userid="+id, // Also I tried with : data: {userid: id},
url: "user-profile.php",
success: function(){
$('#info-user').fadeToggle('slow', 'linear');
alert(id); // I receive the correct id value
}
});
});
});

这是我的 user-profile.php:

<div id="activity_stats">
<h3>Viendo el perfil de <?php echo $_POST["userid"]; ?></h3>
</div>

谁能帮帮我?

谢谢:)

最佳答案

只有我一个人,还是您根本没有使用响应?

$.ajax({
success: function(){
$('#info-user').fadeToggle('slow', 'linear');
}
});

您的匿名 success 函数忽略所有响应。我怀疑你的 #info-user 应该是一个空元素,你没有得到视觉反馈。

一个例子可以是:

$.ajax({
success: function(response){
$('#info-user').html(response).fadeToggle('slow', 'linear');
}
});

其他替代方案可以使用 .load() .

关于php - 如何将 jquery var 发送到 php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10962607/

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