简体   繁体   English

使用jQuery和JSON加载和附加外部html文件

[英]Load and append external html file with jQuery and JSON

I use the following code: 我使用以下代码:

<div id="success"></div>
<script>$.getJSON('http://daytona.bg/test.html', function(data) { $(data.html).appendTo("#success"); } );</script>

The script is loading and appending but only if the test.html is on my computer. 仅当test.html在我的计算机上时,脚本才会加载和追加。 If it's on a external domain - it's not working. 如果在外部域上,则无法正常工作。

How can it be done? 如何做呢?

You'll need to use JSONP, the cross-domain version of JSON to get data from external domain. 您需要使用JSONP(JSON的跨域版本)从外部域获取数据。

Here is a link with a lot of useful information: jQuery AJAX cross domain 这是包含许多有用信息的链接: jQuery AJAX跨域

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

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