javascript - How to know whether PartialView is loaded by JQuery? -
my goal simple - add image in next empty div. example, have 3 divs. if first div not empty, add image second div.
so, have simple view:
<div id="imagedivf"></> <div id="imagedivsecond"></> <div id="imagedivt"></>
a simple partial view:
<img id="hello"/>
ajax code loads partial view div:
$(document).ready(function () { datatype:'json', url: '/home/uploadfiles', autoupload: true, done: function (e, data) { if ($("#imagedivf").has("img").length==0) { $('#imagedivf').load('/home/imagepartialview', { address: data.result.name }); // in next row check whether #imagedivf contains image //i should check whether #imagedivf contains image decide whether necessary put image next empty div //pseudo code: if(#imagedivf) not contain image, image should inserted next div #imagedivsecond }
how check whether '#imagedivf' contains partial view(image inside)? i've tried:
$('#imagedivf').find('#hello');//not detected $(''hello", "'#imagedivf")// not detected $('#imagedivf #hello')// not detected
there callback function in .load(url, data, cb)
method:
$('#imagedivf').load('/home/imagepartialview', { address: data.result.name }, function(){ alert($(this).find('img').length !== 0); // true if image there. });
you have check in callback function because .load()
has async
nature process, doesn't hold code execution. whenever .load()
method executes next line executed because not wait .load()
finished.
that why callback function there, can put code execution in it.
Comments
Post a Comment