【发布时间】:2016-01-20 12:19:58
【问题描述】:
我尝试通过 ajax 加载一个 php 文件。
这段代码可以正常工作:
<body id="top">
<div id="loadajaxhere"></div>
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("loadajaxhere").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("GET", "myfile.php", true);
xmlhttp.send();
</script>
但在我的 php 文件中是 jquery 插件,通过 ajax 加载后无法工作... 也许解决方案是通过 jquery 语法使用 ajax。对吗?
我试过了,但是我的 Ajax 没有加载 php... 它应该通过在定义的 div 中加载页面来自动加载 php。
提前非常感谢!
【问题讨论】:
-
myfile.php的内容是什么? -
有没有JQuery函数调用?请放置该代码。还要检查您的浏览器控制台是否有 JS 错误(如果有)。
-
无需使用 ajax 加载任何 javascript。只需将其添加到当前页面,如有必要,在某些逻辑中。例如stackoverflow.com/questions/15521343/…
-
我通过复制 myfile.php 的内容而不是 来尝试内容。这很好用。内容是普通的html、php和jquery脚本,但这不可能是问题。
标签: javascript php jquery html ajax