Stump the Panel: SharePoint Q&A

Immediate solutions for common SharePoint questions
It is currently Wed Jun 19, 2013 2:59 pm

All times are UTC - 5 hours [ DST ]


Forum rules


What you are viewing is an archive of Stump the Panel. It remains for reference purposes. Please post all new questions on NothingButSharePoint.com
https://www.nothingbutsharepoint.com/sites/eusp/Forum



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: AJAX or Refreshing a DVWP in 2007
PostPosted: Thu May 12, 2011 8:22 am 
Offline
User avatar

Joined: Mon Jan 04, 2010 1:15 am
Posts: 1839
Location: North Carolina
I've got a DVWP I constructed that is pulling some information from 2 lists. Because the data needs to be somewhat fresh, I'm looking at ways to make the web part auto refresh. If this was 2010, I'd be in business, but since I'm on 2007 still, what are my options for refreshing the web part?

Ideally, I'd like to have the web part in a div or iframe and have it refresh every 20-30 seconds without forcing a full page fresh.


Top
 Profile  
 
 Post subject: Re: AJAX or Refreshing a DVWP in 2007
PostPosted: Thu May 12, 2011 8:32 am 
Offline
User avatar

Joined: Sat Jan 02, 2010 6:02 pm
Posts: 1035
Location: Silver Spring, MD
Here's what I'm thinking. Marc correct me if I'm wrong on this.
Code:
function AutoLoadDVWP() {
   $("#waitMessage").show();
   $('#Report').load('ADiffPage.aspx #ElementID', function() {
         $("#waitMessage").hide();
         setInterval('AutoLoadDVWP()', 3000); //loads every 3 seconds
      });
};

So this code should autorun itself every 3 seconds. It'll load whatever you have from ADiffPage.aspx within the element with an id='ElementID'. I typically wrap a div around the webpart I want to load in, but anything would work.


Top
 Profile  
 
 Post subject: Re: AJAX or Refreshing a DVWP in 2007
PostPosted: Thu May 12, 2011 8:45 am 
Offline

Joined: Tue Jan 05, 2010 5:59 am
Posts: 145
Looks good Matt! I do something similar with the jQuery UI dialog but the concept is the same.


Top
 Profile  
 
 Post subject: Re: AJAX or Refreshing a DVWP in 2007
PostPosted: Thu May 12, 2011 8:51 am 
Offline
User avatar

Joined: Mon Jan 04, 2010 1:15 am
Posts: 1839
Location: North Carolina
So how does the ADiffPage.aspx work in this scenario? Is it just an aspx page with the DVWP, no attachement to the master page, no web part zones, etc, that gets sucked in? Does the aspx respect the layout of the div it's being sucked into or does it try to render it similarily to the page viewer web part?


Top
 Profile  
 
 Post subject: Re: AJAX or Refreshing a DVWP in 2007
PostPosted: Thu May 12, 2011 8:58 am 
Offline
User avatar

Joined: Sat Jan 02, 2010 4:29 pm
Posts: 589
Location: Boston, MA, USA
Here's what I was thinking. I haven't done it, but it seems faily easy.

Load the current page with AJAX, parse it to grab the Web Part you want to refresh, and replace it in the DOM. It has nothing to do with the Web Services or formatting or anything hard; just grabbing the right bit of the DOM and using it.

Matt's on basically the same track, but I'm not sure of his code. There's no need for some special page, though.

M.


Top
 Profile  
 
 Post subject: Re: AJAX or Refreshing a DVWP in 2007
PostPosted: Thu May 12, 2011 9:14 am 
Offline
User avatar

Joined: Sat Jan 02, 2010 6:02 pm
Posts: 1035
Location: Silver Spring, MD
The ADiffPage.aspx would live somewhere within your site collection. It doesn't need to be attached to the masterpage or web part zones. I add them anyway, just in case a curious user finds themselves there.

The .load() method in my example needs to have a different page, so when the code is ran, the DVWP is rendered again. That's what updates the info. Marc, as always, has a cleaner method. There's no muss, no fuss, with a separate page. The code may be a bit more involved though.

I'm guessing if you have a look at the SPServices source code, you'll see an example of what Marc is saying. I'm pretty sure SPCurrentUser uses this .ajax() method.


Top
 Profile  
 
 Post subject: Re: AJAX or Refreshing a DVWP in 2007
PostPosted: Thu May 12, 2011 9:34 am 
Offline
User avatar

Joined: Mon Jan 04, 2010 1:15 am
Posts: 1839
Location: North Carolina
So if my web part is wrapped in a div with an id of offerings and lives on my home page, https://mydomain/sites/sitecoll/pages/default.aspx, you're saying to have a script that will AJAX the current page, parse the AJAXed content for my offerings div, and replace the existing div with a new one?

I'm not sure I could even pseudo code what that would look like.


Top
 Profile  
 
 Post subject: Re: AJAX or Refreshing a DVWP in 2007
PostPosted: Thu May 12, 2011 9:56 am 
Offline
User avatar

Joined: Sat Jan 02, 2010 4:29 pm
Posts: 589
Location: Boston, MA, USA
Matt's right that SPGetCurrentUser would be a good thing to look at. Remember that HTML pages are really XML pages, so you can parse them just as you would the output from a Web Service call.

M.


Top
 Profile  
 
 Post subject: Re: AJAX or Refreshing a DVWP in 2007
PostPosted: Thu May 12, 2011 11:06 am 
Offline
User avatar

Joined: Mon Jan 04, 2010 1:15 am
Posts: 1839
Location: North Carolina
So something like this? I have to be honest, I'm just not understanding what to actually do.
Code:
$.ajax({
   async: false,
   url: "https://mydomain/sites/sitecoll/pages/default.aspx",
   complete: function (xData, Status) {
      $(xData.responseText).find("#offerings").each(function() {
               if(thisTextValue.test($(this).html())) {
                  //do something
                  return false;
               }
            });
         }
      });
return thisField.replace(/(^[\s\xA0]+|[\s\xA0]+$)/g, '');
$(#offerings).thisField


Top
 Profile  
 
 Post subject: Re: AJAX or Refreshing a DVWP in 2007
PostPosted: Thu May 12, 2011 11:15 am 
Offline
User avatar

Joined: Sat Jan 02, 2010 4:29 pm
Posts: 589
Location: Boston, MA, USA
Sorta. You'll need to identify what selector will work in the page and to grab the markup from the DOM you get back in the AJAX call, and I'm guessing that '#offerings' isn't it.

And you've got some bits from my code that have no use here. It'll be simpler, something like this:
Code:
$.ajax({
   async: false,
   url: "https://mydomain/sites/sitecoll/pages/default.aspx",
   complete: function (xData, Status) {
      var DVWPMarkup = $(xData.responseText).find("#offerings").html();
      $(#offerings).html(DVWPMarkup);
    }
});

M.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group