Javascript jquery首次出现延迟加载错误
我的AJAX请求Javascript jquery首次出现延迟加载错误,javascript,jquery,caching,jquery-lazyload,Javascript,Jquery,Caching,Jquery Lazyload,我的AJAX请求 $.ajax({ type: "POST", data: "{'id':'" + id + "'}", contentType: "application/json; charset=UTF-8", dataType: "json", url: "../WebService.asmx/getallimages", success: function (data) { //getting image srcs her
$.ajax({
type: "POST",
data: "{'id':'" + id + "'}",
contentType: "application/json; charset=UTF-8",
dataType: "json",
url: "../WebService.asmx/getallimages",
success: function (data) {
//getting image srcs here
for (var i = 0; i < s; i++) {
counter_xyz++;
if(counter_xyz<10) {
$("#holding_img_" + variable[i]).attr("src", variable[i].src);
} else {
$("#holding_img_" + variable[i]).attr("data-orig", variable[i].src);
}
}
$("img.lazy").show().lazyload({
data_attribute: "orig"
});
}
error : function (data) {
}
});
$.ajax({
类型:“POST”,
数据:“{id':'”+id+“}”,
contentType:“应用程序/json;字符集=UTF-8”,
数据类型:“json”,
url:“../WebService.asmx/getallimages”,
成功:功能(数据){
//在这里获取图像src
对于(变量i=0;i如果(计数器)_xyz我猜成功回调后逗号丢失了。请检查一下。确保将代码保存在内部
$(document).ready(function(){});
这可能会有帮助
$(document).ready(function()
{
//Your ajax call..
});
我看到了您正在谈论的问题…没有深入调查以理解为什么会发生这种情况-但这里有一个解决方案:加载脚本(JQuery和LazyLoad),而不使用
使用浏览器缓存,通过使用“loadScript”功能将它们注入页面:
在FF 32.0.3下测试(Chrome中的原始版本-由于lazyLoad脚本中严格的MIME类型策略)
jquerylazyload
for(var i=0;i
。什么是s
?什么是计数器xyz
。?你能为这个问题创建一个在线演示吗?首先,你在错误之前漏掉了逗号。声明数据不应该字符串化:数据:{id:id},
应该可以工作。什么是变量
以及如何处理数据
?成功回调函数后缺少逗号。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JQUERY LazyLoad</title>
</head>
<body>
<img id="holding_img_1" class="lazy"/>
<img id="holding_img_2" class="lazy"/>
<img id="holding_img_3" class="lazy"/>
<img id="holding_img_4" class="lazy"/>
<img id="holding_img_5" class="lazy"/>
<img id="holding_img_6" class="lazy"/>
<img id="holding_img_7" class="lazy"/>
<img id="holding_img_8" class="lazy"/>
<img id="holding_img_9" class="lazy"/>
<img id="holding_img_10" class="lazy"/>
<img id="holding_img_11" class="lazy"/>
<img id="holding_img_12" class="lazy"/>
<img id="holding_img_13" class="lazy"/>
<img id="holding_img_14" class="lazy"/>
<img id="holding_img_15" class="lazy"/>
<script>
"use strict";
function callback(data) {
alert(data);
}
function loadScript(scriptSrc, jqueryLoaded) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.async = false;
script.onload = function(){
if (jqueryLoaded) {
$.ajax({
type: "POST",
//data: "{'id':'" + id + "'}",
contentType: "application/javascript; charset=UTF-8",
dataType: "jsonp",
url: "http://localhost:8080/images/?callback=callback",
success: function (data) {
console.log(data);
//getting image srcs here
for (var i = 0; i < data.length; i++) {
//counter_xyz++;
//console.log(i);
if(i<10) {
$("#holding_img_" + i).attr("src", "http://localhost:8080/image/"+(i+1)+".jpg");
} else {
$("#holding_img_" + i).attr("data-orig","http://localhost:8080/image/"+(i+1)+".jpg");
}
}
$("img.lazy").show().lazyload({
data_attribute: "orig"
});
},
error : function (data) {
}
});
}
else {
loadScript("https://raw.githubusercontent.com/tuupola/jquery_lazyload/master/jquery.lazyload.min.js", true);
}
};
script.src = scriptSrc;
document.getElementsByTagName('head')[0].appendChild(script);
};
loadScript("http://code.jquery.com/jquery-1.11.1.min.js");
</script>
</body>
</html>