2012-08-04 36 views
0

我正在做一個小小的管理面板,想知道是否有可能在點擊面板中的按鈕以在jQuery中添加index.php文件中的div框?jQuery將div添加到另一個頁面

如果是這樣,一個小例子將不勝感激!

+1

谷歌會很快回答這個問題。 – 2012-08-04 15:25:56

回答

0

您需要使用jQuery的$.post()方法來發送XML HTTP POST請求,然後在服務器上的PHP文件修改索引文件,或可包含在索引中的文本文件:

$.post('indexEdit.php', {info: "info to ad to file"}, function(data){ /*callback here*/ }); 

確保indexEdit.php具有會話驗證功能,或者其他人可以嘗試向其發佈信息並執行外部編輯。

0

要將代碼添加到div的開頭,請使用prepend方法。要將代碼添加到div的末尾,請使用append方法。

以下是用於添加代碼的html頁面的正文2個例子:

$("body").prepend("This is some div added to the start of the page."); 
$("body").append("This is some div added to the end of the page."); 

如果你想動態加載的內容,你將不得不使用ajax方法和回調使用上面的代碼。

相關問題