我尝试在单击事件上提交成功之前加载gif图像,但图像仅在第二次或第三次或更多次点击时加载,但不是第一次加载。这是为什么?我尝试过使用beforeSend()&还尝试在ajax调用之前加载图像(将它放在$ .ajax函数之前)。但同样的事情正在发生。 Success()与预期一样有效。 js代码是:
$('.gal').on('click', function(){
//$(‘#gallery').prepend('<img src="http://127.0.0.1:8887/img/spinner.gif" class="spinner">');//load img
$.ajax({
url:"http://127.0.0.1:8887/image gallery.html",
beforeSend:function(){
$('#gallery').prepend('<img src="http://127.0.0.1:8887/img/spinner.gif" class="spinner">');//load img
},success:function(response){
setTimeout(function(){
$('.container').append($(response)).slideDown();
$('html, body').animate({scrollTop:$('#gallery').position().top},500);
},2200);
},
complete:function(){
setTimeout(function(){
$('#gallery').children('img:first-of-type').remove();
},2000);}});
});
这里有什么问题?建议请。
答案 0 :(得分:0)
尝试$(&#39; .gal&#39;)。first()。on({})然后尝试onclick事件
答案 1 :(得分:0)
public function download(Request $request, $id) {
$document = Document::find($id);
$s3 = Storage::disk('s3');
$name = substr($document->link, strrpos($document->link, '/') + 1);
$file = $s3->get($name);
$headers = [
'Content-Type' => 'application/pdf',
'Content-Description' => 'File Transfer',
'Content-Disposition' => "attachment; filename={$name}",
'filename'=> $name
];
return response()->download($file);
}