2016-02-01 42 views
0

如何在使用jQuery加載頁面後發送數據?如何在jQuery中加載頁面後發送數據

例如

$("#target").click(function() { 
     $('#thetag').load(page.php, function(){ 

    $.ajax({ 
    type: "POST", 
    url: "page.php", 
    data: {data: "hi world"}, 
    success: function(result) { 
    console.log('good'); 
     } 
}); 
    }); 
    }); 

</div id="thetag"> 
page.php 

<?php echo $_POST['data'] ?> ==== 'hi world' 
</div> 

我需要加載點擊後page.php文件上#target,並在同一時間,通過AJAX郵寄的數據;顯示#thetag

+0

你會得到什麼結果?你在打開的div標籤中看起來像一個錯誤的'/'。該div內的代碼是否標記page.php上的內容?如果是這樣的話,你應該在div中看到'hi world ===='hi world''。 –

+0

當前結果是什麼?任何錯誤,空白的迴應? – RomanPerekhrest

回答

1

只需發送數據和load()請求。沒有更多的信息,似乎沒有道理做出另一個請求相同的網址

$('#thetag').load(page.php, {data: "hi world"}} 
+0

'.load'執行'GET'請求,而不是'POST'。 – Barmar

+0

如果數據作爲對象提供,則使用POST方法;否則,假定爲GET。 – charlietfl

+0

多年來我一直忽略的一點細節。 – Barmar

相關問題