简体   繁体   English

JavaScript文件不会影响通过jquery load()方法导入的新文件

[英]JavaScript file doesn't effect new file imported via jquery load() method

I have a file index.php and there is a main js script in its header. 我有一个文件index.php,并且标题中有一个主要的js脚本。 I'm using Jquery load method to load other php file inside a div element: 我正在使用jQuery加载方法在div元素中加载其他php文件:

$("#formHideinAjax").load('loginpass.php');

And as our friend explained here the main js file which had loaded in the header doesn't work in new imported file so I was forced to add the js file inside the loginpass.php too(Now I have two same js file, one in header and one in div that loads loginpass.php ! ) I know that this method of loading js file is not standard and sends more request to my server. 正如我们的朋友在这里解释的那样,已加载到标头中的主要js文件在新导入的文件中不起作用,因此我也被迫将js文件添加到loginpass.php中(现在我有两个相同的js文件,其中一个标头和div中的一个加载loginpass.php!)我知道这种加载js文件的方法不是标准的,它会向我的服务器发送更多请求。 How can I fix this problem? 我该如何解决这个问题?

Well, it is explicitly said in $.load() documentation. 好吧,它在$.load()文档中有明确说明。 I'm afraid you can't just paste <script></script> code into your DOM for browser to run it. 恐怕您不能仅将<script></script>代码粘贴到DOM中以便浏览器运行它。

I'm afraid you have to send JavaScript code from your loginpass.php file (without <script></script> tags) and just eval it in your JavaScript 恐怕您必须从loginpass.php文件(没有<script></script>标记)发送JavaScript代码,然后将loginpass.php评估为JavaScript

$("#formHideinAjax").load('loginpass.php', function () {
    // eval JavaScript code from php file here
});

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

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