简体   繁体   English

如何使用Javascript包含/插入HTML文件

[英]how to include/insert HTML file using Javascript

Using Wordpress, I have the file search-form.php in my child theme's folder. 使用Wordpress,我的子主题文件夹中有文件search-form.php

How do I insert this during a JavaScript routine from a file 404.php in the same folder? 如何在JavaScript例程中从同一文件夹中的404.php文件插入此代码?

I've tried using: <script type="text/javascript" src="search-form.php"></script> but this does not output the contents of search-form.php at the place I am calling it from. 我尝试使用: <script type="text/javascript" src="search-form.php"></script>但这在我从中调用它的位置未输出search-form.php的内容。

Help appreciated. 帮助表示赞赏。

You could use php includes: 您可以使用php包括:

<?php include "searchform.php";?>

This runs on server side, wich is good for loading speed. 它在服务器端运行,这对于提高加载速度非常有用。

Or you could use iframes: 或者您可以使用iframe:

<iframe src="searchform.php">Old browser!!</iframe>

Or you could dynamically load it with js/ajax: 或者您可以使用js / ajax动态加载它:

<div id="show">loading...</div>
<script>
body.onload=function(){
 //see ajax tutorials
 document.getElementById("show").innerHTML=ajaxdata;
}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM