非常简单的jQuery .load示例不起作用 [英] Very Simple jQuery .load Example Not Working

查看:83
本文介绍了非常简单的jQuery .load示例不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这是一个非常简单的问题,但我似乎无法完成它的工作。我需要使用JavaScript(特别是jQuery,显然)从页面抓取一些内容,并将其拉入另一个页面。我已经研究了这一点,但似乎无法得到一个非常简单的例子。



这是我试图获取内容的页面从:

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD HTML 4.01 Transitional // EN> 
< html>
< head>
< title>测试< /标题>
< / head>
< body>
< p>这是测试html页面。< / p>
< / body>
< / html>

以下是我试图用来提取内容的页面:

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD HTML 4.01 Transitional // EN> 
< html>
< head>
< title> PullData< / title>
< script type =text / javascriptsrc =http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js>
< / head>
< body>

< ol id =result>< / ol>

< script type =text / javascript>
$('#result')。load('test.html');
< / script>

< / body>
< / html>

当我打开页面时,它似乎没有任何操作。我基本上试图遵循jquery.com中的示例: http://api.jquery.com/load/



这两个html页面都位于C驱动器上的某个文件夹中。



什么是我失踪了?



感谢您的帮助!

您使用的是什么浏览器?



由于同源政策,某些浏览器不允许AJAX请求< file:///

code> URLs,即使原始文件是以这种方式加载的。



你的 .load()是什么,错误处理程序说?哦...

I think this is a very simple question, but I can't seem to get it to work. I need to use JavaScript (specifically jQuery, apparently) to grab some content from a page, and pull it into another page. I've researched this quite a bit, but can't seem to get even a very simple example to work.

Here is the page I'm trying to get content from:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test</title>
</head>
<body>
<p>This is the test html page.</p>
</body>
</html>

Here is the page I'm trying to use to pull the content:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>PullData</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</head>
<body>

<ol id="result"></ol>

<script type="text/javascript">
$('#result').load('test.html');
</script>

</body>
</html>

When I open the page it doesn't seem to do anything. I'm basically trying to follow the examples from jquery.com: http://api.jquery.com/load/

Both html pages are in the same folder somewhere on my C drive.

What am I missing?

Thanks in advance for your help!

解决方案

What browser are you using?

Because of same-origin policy, some browsers won't permit AJAX requests to file:/// URLs, even if the original file was loaded that way. I know this is true of Chrome, but haven't tested others.

What does your .load() error handler say? Oh...

这篇关于非常简单的jQuery .load示例不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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