动态JavaScript加载(xmlhttprequest) [英] Dynamic JavaScript Loading (xmlhttprequest)

查看:333
本文介绍了动态JavaScript加载(xmlhttprequest)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前正在测试:WinVista / IE7

我一直在努力让xmlhttprequest持续数周。我终于得到了一个半工作的脚本。提取文本或xml文件效果很好,并填充到网页中;但是,执行javascript有一些问题:


1.打开空白页面,但不打开页面。它似乎强制覆盖原始页面。我希望它通过在< div>内加载来更新现有页面元素。


2.我似乎无法使功能发挥作用。尽管使用''window''元素,似乎脚本没有在全局空间中打开。


3.我试图加载的外部javascript文件应采用什么格式在吗?我想我已经想出不要包含通常包含在外部javascript文件中的'<! - ''和''// - >''标签。


4.我不知道如何判断浏览器何时使用JScript或JavaScript(friggin''Microsoft :-D)以及两者如何以不同方式响应。


我有在全球问题上已经阅读了很多,但没有一个建议的修复对我有用。我学到的一件事是,在IE7中,启动外部javascript文件的所有这三种方法都可以工作:eval(),execScript()和setTimeout()。


以下是您观看快感的代码(为了便于阅读,我将代码分解;所以如果看起来比正常情况更长,我会道歉):

Currently testing in: WinVista / IE7

I have been working on getting xmlhttprequest going for weeks now. I have finally gotten a semi-working script going. Pulling up text or xml files works great and populates into the webpage; however, executing javascript has a few problems:

1. Opens on a blank page, but not a new page. It appears to compeltely overwrite the original page. I want it to update the existing page by loading within a <div> element.

2. I cannot seem to get functions to work. It seems as if the script is not opening in the global space despite using the ''window'' element.

3. What format should the external javascript file that I am attempting to load be in? I think that I have figured out not to include the ''<!--'' and ''//-->'' tags normally included in an external javascript file.

4. I have no idea how to tell when the browser is using JScript or JavaScript (friggin'' Microsoft :-D) and how the two may respond differently.

I have been reading a lot on the global issues, but none of the suggested fixes has worked for me. One thing that I''ve learned is that in IE7, all three of these methods of initiating an external javascript file work: eval(), execScript(), and setTimeout().

Here is the code for your viewing pleasure (I break my code out for ease of reading; so I apologize if it seems longer than normal):

展开 | 选择 | Wrap | 行号

推荐答案

顺便说一下,这个:

By the way, this:

展开 | 选择 | Wrap | 行号


嗨...


可能是你可以尝试这样的东西:


js-text应该看起来像对responseText的赋值:

hi ...

may be you could try something like this:

the js-text should look like the assignment to responseText:

展开 < span class =codeDivider> | 选择 | Wrap | 行号


感谢您的回复,gits。如果我正确理解您的示例代码,您建议创建一个全局变量并将其设置为等于某个函数。我假设你的意思是函数将是来自xmlhttprequest的responseText。我试过了。基本上我这样做了:

Thanks for the reply, gits. If I understand your example code correctly, you are suggesting creating a global var and setting it equal to some function. I assume you mean the function would be the responseText from xmlhttprequest. I have tried that. Basically I did this:

展开 | 选择 | Wrap | 行号


这篇关于动态JavaScript加载(xmlhttprequest)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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