javascript - Triggering a jQuery Re-Draw After Getting Data With Ajax -


good day, all,

long-time listener, first-time poster...

i have client has been promised seemingly complex bit of functionality. want load contents of 3 separate pages one, after visitor site logs in account. want happen without page refresh. ajax solution. not, however, experienced ajax.

i'm having trouble figuring out how tell when $.get command (using jquery's ajax commands) has finished loading content. approach to, once login has been successful, go , fetch 3 separate pages, load xhtml content variables, , redraw pages. below you'll see pseudo-code. use "xxitemxx" stand-in actual paths. each resulting page i'm trying pull in has div class "content" surrounding data want retrieve. xhtml looks this:

<html>     <head>         <title>page name</title>     </head>     <body>         <div id="header">...</div>         <div class="content">         .         .         .         </div>         <div id="footer">...</div>     </body> </html> 

the jquery code i've built follows. i'm able form submitted , content various .get commands. problem is, can't seem daisy-chain things would. struggling figure out how fire jquery commands draw page once 3 have been retrieved. i'm afraid biggest stumbling point how articulate when searching google see how others have dealt problem. i'm not sure how describe i'm trying accomplish in 10 words or less or in fashion return information need.

can this? i'm afraid have little time , learn.

<script type="text/javascript"> $('xxloginformxx').submit(function () {     $.ajax({           type: $(this).attr('method'),         url: $(this).attr('action'),         data: $(this).serialize(),         beforesend: function() {             $('<div class="loading">loading...</div>').insertbefore('xxloginformxx').css('position','absolute');         },         success: function(data) {               // on successful login, draw page.              $('.loading').fadeout('slow');             var dr_editprofilexhtml, dr_accountorderlistxhtml, dr_wishlistsxhtml;             $.get('xxpathtoeditprofilepagexx', function(data1){                 var dr_editprofilexhtml = $('div.content', data1);             });             $.get('xxpathtoaccountorderlistpagexx', function(data2){                 var dr_accountorderlistxhtml = $('div.content',data2);             });             $.get('xxpathtowishlistspagexx', function(data3){                 var dr_wishlistsxhtml = $('div.content',data3);             });             $('div.content').fadeout(function(){                 $(this).html(dr_editprofilexhtml);                 $('xxeditprofilexhtmlxx').before(dr_accountorderlistxhtml);                 $('xxeditprofilexhtmlxx').before(dr_wishlistsxhtml);             }).fadein();         }     });      return false; }); </script> 

thank time, help, , consideration.

yours, sylvan012

if problem wait 3 requests have returned, then:

  1. store results in variables scoped bit higher each of callbacks can access them
  2. add variable drawing in same scope
  3. in each of callbacks, check if 3 variables non-null , drawing false
  4. if that's case, set drawing true, , work

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -