Reputation: 107
I want to implement deletecomment function in my website but I don't want my users too wait to get result from the server after the ajax request is made, instead want to call some action asynchronously alongwith the request by this way in case if some server is down or something it will show you that the action is done, but actual result can be viewed by refreshing the page, but user must not wait..
My ajaxButton:
$options=array(
"type"=>"post",
"data"=>array("comment_id"=>$comment->id),
);
echo CHtml::ajaxButton('Delete',CController::createUrl('deletecomment'),$options);
What I want to do is make the comment div disappear whose id is comment_{$comment_id}..
Upvotes: 1
Views: 1303
Reputation: 11264
Since ajax is asynchronous javascript and xml it will not wait for your result and start other actions specified what you can do is provide some action in htmloptions array as onclick event and action as hide your block...
This code might work..
$options=array(
"type"=>"post",
"data"=>array("comment_id"=>$comment->id),
);
echo CHtml::ajaxButton('Delete',CController::createUrl('deletecomment'),$options,array("onclick"=>"$('#comment_".$comment->id."').hide()"));
Upvotes: 2