-1
我做了一個wordpress插件,其中我有幾個div。 我想用下面的代碼來獲取div的內容。使用Ajax在wordpress數據庫中存儲html內容
var arhive = j("div.page2").html();
console.log(arhive);
工作正常,問題是當我試圖將它發送到服務器來更新數據庫與新的內容。
j.ajax({
url: "send_data.php",
type: "post",
data: {html: arhive} ,
success: function (response) {
// you will get response from your php page (what you echo or print)
console.log("success");
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
這是我的send_data.php文件的內容。
$var = $_POST["html"];
$my_post = array(
'ID' => 4137,
'post_content' => '$var',
);
// Update the post into the database
wp_update_post($my_post);
echo "success";
我不知道爲什麼,但我得到500錯誤,數據不會存儲任何想法可能會導致此?
什麼問題?你有沒有試過先編碼'archive'?你有沒有試過像'data:{html:archive}'格式正確地發送它? – Justinas
你好,不,我想我設法做這一步,我的問題可能在PHP方面。在它上面工作。 –
以上評論應該幫助您將格式正確的html代碼格式化爲變量「html」。在PHP上,您可以使用$ _POST [「html」]訪問數據。並將其存儲到數據庫中,您可以檢查此:http://www.w3schools.com/php/php_mysql_insert.asp –