gpt4 book ai didi

javascript - 使用 jQuery .load() 仅接收图像的字节码

转载 作者:行者123 更新时间:2023-11-28 20:13:13 26 4
gpt4 key购买 nike

我正在使用 jQuery .load() 接收加载图像的字节码.

是吗

  1. 因为没有指定 MIMEType?
  2. 因为我使用的图像网址没有文件扩展名?
  3. 因为我必须以某种方式包装整个事情?

这里是一些示例代码:

HTML

  <div class="slide" data-img-src="http://lorempixel.com/200/100/technics/">
<div class="slide-content">
<h1>Heading 1</h1>
<p>Just some random text for demonstration purposes.</p>
</div>
</div>

<div class="slide" data-img-src="http://lorempixel.com/200/100/nature/">
<div class="slide-content">
<h1>Heading 1</h1>
<p>Just some random text for demonstration purposes.</p>
</div>
</div>

Javascript

var ajax_load = "<img src='img/load.gif' alt='loading...' />";

$(".slide").each(function(index, el) {
var img_src = $(this).attr('data-img-src');

$(this).prepend(ajax_load);
$(this).load(img_src, null, function() {
console.log(img_src + " loaded");
});
});

还有一把 fiddle http://jsfiddle.net/BCLJE/

最佳答案

您需要确保您尝试检索的数据或 HTML 片段位于同一域中。由于同源政策

http://en.wikipedia.org/wiki/Same_origin_policy

Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.

附加注释下的load() API简写方法:

http://api.jquery.com/load/

关于javascript - 使用 jQuery .load() 仅接收图像的字节码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19592602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com