PHP/AJAX只在回显时工作
PHP/AJAX only works when something gets echoed?
我试图将Wordpress博客头包含在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");
该代码仅在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);
是什么导致了这种行为?
试试这个:
<?php
define('WP_USE_THEMES',false);
require(explode("wp-content",realpath(dirname(__FILE__)))[0].'wp-blog-header.php');
?>
相关文章:
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- Rails-JQueryUIAutcomplete和AJAX不工作,可以't连接到数据库
- jQuery Ajax GET请求工作不正常
- jQuery触发器点击未从AJAX成功工作
- Jquery/Ajax.serialize()未完全工作
- 如何检查这个代码点火器php函数是否工作,该函数是否在ajax url中使用
- .load ajax无法正常工作whitin wordpress主题
- AJAX更新面板不;t工作.请帮我找出我错在哪里.
- 点击功能没有'ajax调用动态元素(Backbone)后无法工作
- Javascript作用域和Ajax调用;工作不正常
- Jquery ajax方法请求体为null,但poster工作正常
- 用户名输入如果其他块不能正常工作/Javascript-jQuery-AJAX
- XMLHttpRequest在$.ajax工作的地方给出了CORS错误
- show-hide只在ajax调用中第一次工作
- 当阻止Enter键提交AJAX表单时,关注下一个输入是't工作
- Fancybox未按预期工作(ajax)
- $的工作.ajax json回调函数
- 删除功能不能正常工作- Ajax
- yii2:处理gridview的选定行不工作- ajax post是空的
- Onchange函数不工作ajax