我試圖在PHP文件中包含Wordpress博客標題以將其用作AJAX調用函數。PHP/AJAX只有在回顯時才起作用?
define('WP_USE_THEMES',false);
echo 'Something';
require(explode("wp-content",realpath(dirname(__FILE__)))[0].'wp-blog-header.php');
原始片段中找到:Wordpress include("../../../wp-blog-header"); failing,由OLE Sauffaus電流。
該代碼僅在define
和require
函數之間有回顯或打印時才起作用。沒有它,服務器會迴應一個404錯誤。
只有當我通過AJAX請求如下面的目標php時,纔會出現此行爲。
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById('directory_results').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("POST", "http://localhost:8888/appsconnected/wp-content/themes/appsconnected/ajax-loop.php");
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send("platform=" + platforms + "&category=" + category + "&orderby=" + order);
是什麼原因導致此行爲?
你缺一 ''在'$ path'-assigment我相信 –
這裏有一些非常奇怪的代碼人工製品:'$ scriptPath。 '/./''...這裏有什麼'/./'?還有'''。$ filepath [0]。'/ wp-blog-header.php' ...什麼是'''.'用於? – arkascha
我不太確定他們的用途。如前所述,我發現這個代碼是關於獲取wp-blog-header的另一個問題的答案。但是回顯或打印一些東西不應該對周圍的代碼有任何影響嗎? – Rijk