I am loading a page using $Ajax and upon success i run a toggle function. Now how can i set it up so that once its been loaded it will not make a second Ajax request? Basically a user clicks edit and i get the form via Ajax request and place it into a div. Once completed the original content toggles to the newly loaded form. If a user clicks cancel the form toggles revealing the original content. But if they click edit again it runs the request to get the form. But since its already been loaded and now just hidden in the div so i do not need to make the Ajax request call again $("a#mod_test").click(function(){ $('#test').after('<div class="loading"></div>'); $('.loading').fadeIn('normal'); $.ajax({ type: "POST", url: '/manage/account/edit', cache: true, success: function(data){ $('.loading').fadeOut('normal').remove(); $("#test").slideToggle('slow').toggleClass("hidden"); $("#testForm").html(data).slideToggle('slow'); } }); return false; });
How can I set a variable in the success function so that when the user clicks it checks to see if its been loaded already Something like this I tried but no go if (loadedAlready = false) { $.ajax({ type: "POST", url: '/manage/account/edit', cache: true, success: function(data){ loadedAlready = true; $('.loading').fadeOut('normal').remove(); $("#test").slideToggle('slow').toggleClass("hidden"); $("#testForm").html(data).slideToggle('slow'); } }); } else { $('.loading').fadeOut('normal').remove(); $("#test").slideToggle('slow').toggleClass("hidden"); $("#testForm").slideToggle('slow'); } Dave