I was hoping someone can point out why my div (in my case, I use li) isn't hiding using jquery upon successful execution of my php script.
Here is my query code (from jquery impromptu plugin):
if(v){
var bid = f.bannerid;
$.post('/manage/<?=CFILE?>',{bannerid:f.bannerid,action:'deleteBanner',cid:<?=$contentid?>,uid:'<?=$_SESSION['userid']?>'},{callback:function(data){
if(data=='true'){
$('#list_'+bid).hide('slow', function(){ $(this).remove(); });
}else{
$.prompt('An Error Occured while removing this banner');
}
}});
}
here is part of my html code:
<li id="list_47">
<div>
<div id="row">
<div class="title id="bannerid59"><img src="banner_45_10.jpg" /></div>
<div class="action"><a href="javascript:;" title="Delete Banner" class="deleteBanner" onclick="deleteBanner(59);">Delete</a></div>
</div>
<div id="row-right">
<span class="small">Sort Order: 2</span><br>
</div>
</div>
</li>
<li id="list_48">
<div>
<div id="row">
<div class="title id="bannerid60"><img src="banner_45_11.jpg" /></div>
<div class="action"><a href="javascript:;" title="Delete Banner" class="deleteBanner" onclick="deleteBanner(60);">Delete</a></div>
</div>
<div id="row-right"&开发者_如何学JAVAgt;
<span class="small">Sort Order: 3</span><br>
</div>
</div>
</li>
Finally, here is my simple php code:
if(isset($_POST['action']) && $_POST['action']=="deleteBanner"){
mysql_query("DELETE FROM banner where banner_image='".$_POST['bid']."' AND users_id='".$_POST['uid']."'") or die(mysql_error());
print "true";
exit;
}
I am able to delete my banner from mySQL database without any problem using these codes but i can't seem to hide the deleted li (for example, list_47) upon script execution.
Any help is appreciated. thanks.
You're not calling $.post
correctly, your {callback: function() ... }
is supposed to be just the function:
$.post(
'/manage/<?=CFILE?>',
{bannerid:f.bannerid,action:'deleteBanner',cid:<?=$contentid?>,uid:'<?=$_SESSION['userid']?>'},
function(data) {
// ...
}
);
$.post
will look for a function in its argument list but won't find one; since there is no callback function passed, no callback will be called and your <div>
won't be hidden.
Compare these two:
- Pass a function and it works.
- Pass
{callback:function() {/*...*/} }
and it doesn't work.
精彩评论