在我的WordPress插件的管理頁面中,我有一個函數可以調用一個PHP文件的ajax。如果一切順利,這個php文件應該更新wordpress中的選項。但由於某些原因,當我嘗試使用update_option時,它不起作用。update_option不能在單個php文件中工作
這裏是我的activate.php:
if(isset($_GET['activate']) && $_GET['activate'] == "true") {
if(isset($_REQUEST['txtAC']) && isset($_REQUEST['txtKey'])) {
$ac = $_REQUEST['txtAC'];
$key = $_REQUEST['txtKey'];
if($ac != "" && $key != "") {
$api_url = "http://192.168.2.75/wouter/yii2/basic/web/cars/activate/" . $ac . "/" . $key;
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $api_url);
$result = curl_exec($ch);
curl_close($ch);
$count = json_decode($result);
if($count == 1){
update_option("ac", $ac);
update_option("auth_key", $key);
echo "success";
} else {
echo "failed";
}
return;
} else {
echo "notSet";
return;
}
}
return;
}
所以一切順利,直到該update_option。當我把它們放入時,什麼都沒有發生,並且服務器錯誤。
我在做什麼錯?
編輯
因此,這裏是我的jQuery Ajax代碼:
function activatePlugin() {
jQuery("#acError").html("");
jQuery("#keyError").html("");
var txtAC = document.getElementById("txtAC").value;
var txtKey = document.getElementById("txtKey").value;
if(txtAC == "") {
jQuery("#acError").html("Vul een klantnummer in");
}
if(txtKey == "") {
jQuery("#keyError").html("Vul een key in");
}
if(txtAC != "" && txtKey != "") {
jQuery.ajax({
url: "../wp-content/plugins/autocommerce/admin/activatePlugin.php?activate=true",
method: "POST",
data: { txtAC : txtAC, txtKey: txtKey }
}).done(function(msg) {
alert(msg);
if(msg == "success") {
location.reload();
} else if(msg == "failed") {
jQuery("#activateError").html("Gegevens onjuist. Controleer uw gegevens en probeer het opnieuw.");
} else if(msg == "notSet") {
jQuery("#activateError").html("Een of meerdere velden zijn onjuist ingevuld.");
} else {
alert(msg);
jQuery("#activateError").html("Er is een fout opgetreden. Probeer het later opnieuw.");
}
});
}
你會得到什麼輸出? '成功','失敗'或'notSet'。當你說有服務器錯誤時,它是什麼?它在PHP錯誤日誌? nginx/apache錯誤日誌? – Latheesan
*「和theres一個服務器錯誤。」* - 究竟是什麼* * –
如果我刪除update_option。我會得到「成功」 –