如何将jquery变量发送到php?
当我尝试用jquery发送var时,ajaxphp没有收到它,我也不知道为什么 这是我的剧本:如何将jquery变量发送到php?,php,jquery,ajax,Php,Jquery,Ajax,当我尝试用jquery发送var时,ajaxphp没有收到它,我也不知道为什么 这是我的剧本: function showHiddenUserInfoPanel(id){ $(document).ready(function(){ $('#admin-resume').fadeToggle('slow', 'linear', function(){ $.ajax({ async: true, type: "POST",
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');
}
});
另一种方法是使用。使用Fiddler跟踪HTTP请求并检查请求是否正确……为什么在函数内部使用
$(document).ready()
?在调用函数之前,您希望等待文档准备就绪,但在函数本身中,它可能无法完成预期的操作。这意味着您实际上并没有在该函数中执行某些操作,您只是绑定到一个事件。@David好吧,如果DOM已经准备好,该函数将立即被调用。@ZombieHunter在我的firebug中出现:userid 11,在控制台选项卡中,David我认为像lonesomeday。您说过“php没有收到它”。你怎么知道的?您是否在单独的窗口或选项卡中打开了“user profile.php”?只需添加更多信息,jQuery.load()
函数也可能对他的需求有用:@Alexander for load()与ajax()相同,但只包含数据、url和回调?谢谢:)@jask,url,数据和回调按顺序;)感谢您的帮助:),但我不需要响应,真的吗?如果您不使用响应,那么您将无法获得user profile.php
的内容(在使用userid
参数发送请求之后)