Change only a part of a web page content

Discussion in 'JavaScript' started by Giber, Aug 2, 2009.

  1. #1
    I need to change a part of my web page content dynamically
    without refreshing the entire page. Like myspace or facebook users gallery.

    Anybody knows for a good quality link of a tutorial or any useful scripts
    with working back button and changing address URL accordingly?

    Thanks for any suggestion.
     
    Giber, Aug 2, 2009 IP
  2. XDMCoder

    XDMCoder Peon

    Messages:
    50
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Dynamic update of some part of a page - AJAX.
    You can read about it at W3Schools.com.
     
    XDMCoder, Aug 2, 2009 IP
  3. Giber

    Giber Well-Known Member

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    101
    #3
    Cool tutorial but I need something more complex...

    If you observe myspace it handles:

    -Back/Forward Button
    -Bookmarking/Creating shortcut
    -Full URL in the address bar
    -Full URL link in the left botom of the status bar

    There are a lot of tutorials about, but all for begginers or just partial solutions.

    I need a professional complete scene.

    However, Thank You.
     
    Giber, Aug 2, 2009 IP
  4. demolisher

    demolisher Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If it is a simple update I'd user jQuery to periodially poll something in the background and update the page accordingly.

    http://docs.jquery.com/Ajax

    setTimeout(poll, 10000); // every 10 seconds

    function poll(){
    $.get('my_url_returns_a_chunk_of_html', myCallback);
    }
    function myCallback(data, textStatus){
    $('#somediv').html(data); // just replace a chunk of text with the new text
    setTimeout(poll, 10000);
    }
    This could be a lot better and handle when the text hasn't changed and error handling etc but is a start.

    If you need it to be instant your looking at Comet but in general it adds a lot of complexity so I'd stay away out of simplicity.

    http://en.wikipedia.org/wiki/Comet_%28programming%29
     
    demolisher, Aug 3, 2009 IP
  5. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #5
    er, if you also observe their usability data, people are leaving myspace like its the titanic 2...

    it's true, you can build a site that does not change url and uses ajax only to fetch data and update parts as needed. but this is really crap with regards to usability. first off - you can't easily bookmark it. pressing back / forward on the browser WILL have unexpected results.

    the url management is doable as anchors to a degree so you can restore the view based upon a url - but it's just silly.

    don't get me wrong, i am all for dyanmic updates of dom elements through ajax or otherwise - just don't think it has to take over and modify the browser and user behaviours.

    also, consider the SEO - you'd only ever broadcast 1 page which then goes and fetches NN smaller 'content' ones as barebones data - you need to be careful how you structure it, I have seen some piss poor attempts at doing this.

    as a whole, it is achievable - but it's hard to get it right. which - i imagine - is why you are struggling to find an out of the box solution for this or a tutorial...

    if you want a second opinion, I suggest you go to www.stackoverflow.com and post your question there - you will get the best advice as voted by your coding peers and be able to take it from there.

    good luck and be sure to post resulting work here - just curious :)
     
    dimitar christoff, Aug 3, 2009 IP
  6. runspace

    runspace Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I just checked out stackoverflow.com. Is this a fairly popular site in the developer community right now?
     
    runspace, Aug 5, 2009 IP
  7. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #7
    yes, it's the top place for coding advice as far as i can tell... depends on the subject though, some tags are more popular than others.
     
    dimitar christoff, Aug 6, 2009 IP