當我嘗試使用jQuery發送var時,ajax php沒有收到它,我不知道爲什麼。我如何發送一個jQuery var到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
}
});
});
});
這是我的用戶profile.php:
<div id="activity_stats">
<h3>Viendo el perfil de <?php echo $_POST["userid"]; ?></h3>
</div>
能有人能幫助我嗎?
謝謝:)
使用Fiddler跟蹤HTTP請求並檢查是否正確... – CodeZombie
爲什麼在函數內使用'$(document).ready()'?你希望等到文檔準備好之後再調用函數,但是在函數本身中它可能不會達到你期望的效果。這意味着你實際上並沒有在這個函數中做什麼,你只是綁定了一個事件。 – David
@David好吧,如果DOM已經準備就緒,這個函數將立即被調用。 – lonesomeday