Skip to content

Instantly share code, notes, and snippets.

@piyushranjan
Created January 5, 2011 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piyushranjan/766174 to your computer and use it in GitHub Desktop.
Save piyushranjan/766174 to your computer and use it in GitHub Desktop.
function create_remotes(){
$("a._remote_").live('click', function(){
href=$(this).attr("href");
method="GET";
if($(this).hasClass("self")){
href=href+(href.indexOf("?")>-1 ? "&" : "?")+$(this).parent().serialize();
method="POST";
}
a=$(this);
a.after("<img id='spinner' src='/images/spinner.gif'/>");
$.ajax({
type: method,
url: href,
success: function(data){
if($(a).attr("id") && $("#container_"+$(a).attr("id")).length>0){
$("#container_"+$(a).attr("id")).html(data);
}else if($(a).attr("id") && $("#"+$(a).attr("id")).length>0){
$("#"+$(a).attr("id")).html(data);
}else{
$(a).after(data);
$(a).remove();
}
$("#spinner").remove();
},
error: function(xhr, text, errorThrown){
txt = "<div class='error'>"+xhr.responseText+"</div>";
$(a).after(txt);
$("#spinner").remove();
}
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment