使用$ .getScript(jquery):不执行代码 [英] Using $.getScript (jquery): code is not executed

查看:362
本文介绍了使用$ .getScript(jquery):不执行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力更新我的网站,该网站现在使用AJAX引擎。我的引擎运行良好,由于某种原因,某些页面不执行javascript,请让我解释一下:当锚更改时我使用$ .get进行数据恢复。页面具有以下结构:

I am working on updating my website, which now uses an AJAX engine. My engine works well, up-to-hand for some reason some pages do not execute javascript, let me explain: when the anchor change I use $.get for data recovery. The pages have this structure:

title
h1
script1.js,script2.js,etc.js
style1.css,style2.css,etc.css
<!--there's the page's content-->

看来重新加载页面解决了问题,但我不明白有什么不同。在前面的代码中,引擎成功运行,重新加载或不加载:

It appears reload the page solves the problem, but i don't understand what is different. In the previous code, the engine runs successfully, reloaded or not:

$.getScript("script1.js");
$.getScript("script2.js");
$.getScript("etc.js");



此外,php生成的脚本包含用户当前的状态对象形式:


In addition, a php generated script contains user's current state under an Object form:

$(function(){
    user = new Object();
    user.id = user.logged = <?php echo $user->getId();?>;
    user.nick = "<?php echo $user->getNick();?>";
    user.mail = "<?php echo $user->getMail();?>";

    user.logout = function(){

    };
});

$ .getScript请求成功,但用户对象未更改。但是,该脚本尚未修改。并且它也不适用于控制台。


此更新目前在 v2.wawolf上在线.com ,你会找到你需要的一切。
Hotlink: 引擎代码

The $.getScript request is successful, but the user object is not changed. The script, however, has yet been modified. And it don't works from console too.

The update is currently online at v2.wawolf.com, you'll find everything you need. Hotlink: Engine's code

推荐答案

我刚刚解决了我的问题:当加载所有文档时,$(function(){})将无法再次使用,所以调用使用$(function(){})的脚本将无法运行。我将它从我所有的二次调用脚本中删除,现在一切正常!

I just solved my problem: when all document is loaded, $(function(){}) will not work again, so calling a script which uses $(function(){}) will no get run. I removed it from all my secondary-called scripts and now all works perfectly!

这篇关于使用$ .getScript(jquery):不执行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆