如何使用<script src =“”>在页面中插入表单

时间:2016-10-21 08:57:15

标签: javascript php jquery

我有这个脚本

&#xA;&#xA;
 &lt; script type =“text / javascript”src =“http:// localhost / wordpress / wp-content / themes / formaz / export.php?id = 74459533“&gt;&lt; / script&gt;&#xA;  
&#xA;&#xA;

我想将其粘贴到我想要的位置它为我加载一个表格。 export.php中的代码是:

&#xA;&#xA;
 &lt; script type =“text / javascript”&gt;&#xA;&#xA; function getQuery(name){&#xA; if(name =(new RegExp('[?&amp; amp;]'+ encodeURIComponent(name)+'=([^&amp; amp;] *)'))。exec(location.search))&#xA; return decodeURIComponent(name [1]);&#xA; }&#XA;&#XA; var id = getQuery(“id”);&#xA;&#xA; document.write(“&lt; div style = \'width:100%; margin:0px auto \'&gt;&lt; iframe src ='http://localhost/wordpress/wp-content/themes/formsaz/formexport.php ?id =“+ id +”'scrolling ='no'frameborder ='0'hspace ='0'width ='100%'height ='100%'&gt;&lt; / iframe&gt;&lt; / div&gt;“) ;&#XA;&#XA; &lt; / script&gt;&#xA;  
&#xA;&#xA;

这从数据库获取id并查找数据,然后将创建的数据返回到第一个脚本所在的页面粘贴。但它不起作用!关于我该怎么做的任何建议?

&#xA;

1 个答案:

答案 0 :(得分:0)

您可以动态添加脚本(因为您的export.php会返回一个javascript):

var jsElm = document.createElement("script");
jsElm.type = "application/javascript";
jsElm.src = "http://localhost/wordpress/wp-content/themes/formsaz/export.php?id=74459533";
document.body.appendChild(jsElm);

或添加iframe

var iframe = document.createElement('iframe');
iframe.style.display = "none";
iframe.src = "http://localhost/wordpress/wp-content/themes/formsaz/export.php?id=74459533";
document.body.appendChild(iframe);

当您的脚本返回数据时,如果可能,您还应该考虑ajax来电。