Replacing one image with another image through ajax makes it dissappear for a split second

Replacing one image with another image through ajax makes it dissappear for a split second

I have the following code (, jquery) (i have simplified the example to show the issue) where i want to click on an image and have it replaced with another image.

This works fine but the first time i click it, the original image disappears (for a split second) before the other image shows up. After that it works seamlessly.

Is there any way to eliminate this quirk so there is not split second where no image is shown?

Here is my controller code:

    public ActionResult UpdateFavoriteExercise(int id, string toggle)     {         if (toggle == "off")         {             return Content("<img toggle='off' src='/images/vote-favorite-off1.png' border=0'>");         }         return Content("<img toggle='on' src='/images/vote-favorite-on1.png' border=0'>");     } 

Here is my jquery code:

$('div.favoriteExercise').live('click', function() {      var id = $(this).attr("id");      var toggle = $(this).attr("toggle");     if (toggle == 'off') {         onOff = 'on';     }     else {         onOff = 'off';     }      var url = '/Tracker/UpdateFavoriteExercise/' + id + '?toggle=' + onOff;      $(this).load(url);     $(this).attr("toggle", onOff); }); 

ASP.NET MVC Form with multiple dropdowns and checkboxes group


Having a class and ID together in an HTMLHelper method. ie. Text
You could try preload the new image with javascript, without javascript or with css.. Is there any reason I should NOT auto-trim html form parameters? Ananother option is to use sprites this ensure the image is already loaded.. mvc model item passed in to dictionary is of type List These are just a few tricks you must try, there are plenty more if you did a bit of googling :). Why is my selected value showing up twice in a dropdownlist ( mvc) In fact, I'd suggest using a single sprite on a single element, and then using background-position in the CSS to switch the focus. Interface arguments in ASP.NET MVCThat way, you must just add/remove a single class from the element, without having to add/remove new elements and did all this testing logic.. Auto generate grid using mvccontrib by passing datatable in MVC 2 application
WebMatrix, ASP.NET Razor, IIS Developer Express, SQL Server Compact Edition - What is Microsoft objective behind these new technologies?

62 out of 100 based on 47 user ratings 322 reviews