SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with Ajax

    There doesn't appear to be an Ajax section, so this is where my problem fits best.

    I recently got the Ajax Sitepoint book, and I'm having problems with it and Ajax. I just finished chapter 3, and for some reason I'm having problems understanding the code. Usually I'm pretty good with things like this, but this is different for some reason. The book uses OOP and I'm not extremely familiar with it. I also think the author doesn't have very good explanations either. So one question I have is, is Ajax possible without OOP? I'm not really talking about the XMLHttpRequest object, but instead of creating your own classes and methods, to simply do plain old functions.

    Something that's really frustrating with the book is the fact that some of the code in the book is different than the downloadable sample code. This does not work well when I type some of the code from the book and copy other lines. Also the fact that my code somehow stopped working (and the downloaded files aren't working perfectly in a certain folder) isn't helping.

    Another problem is that I'm still unclear as to what Ajax is. I understand that it uses the XMLHttpRequest object and changes content on pages without having to reload it. But can't this be done with plain old javascript timers? I mean I've done games strictly in javascript where the content changes, and one was active enough that one could have been fooled thinking it was done with Flash. So what's the difference between Ajax and simple javascript timers?

    I think that's it for now.

  2. #2
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will soon understand how ajax works by coding a small program, likes live search or live add/delete data from database.

    Using XMLHttpRequest you can actually change the data status of your web application without reload the current page. Javascript without XMLHttpRequest can only change the 'representational' status of a web page.

    Say you have a 'big page' with 1000 data records displayed on as a list, and you want to delete one from the list.

    Using ajax, you could submit an ajax request to delete a record, then hide the record that has been deleted. Other records are still on the page, you don't need to reload them.

    Using 'web 1.0', you have to reload the 'big page', it requests the server gets the list records again, the client side displays the list again. Thats why people say ajax application is faster.
    Watisfy - Weight Control Made Easy
    Ruby on rails and Ajax
    http://www.watisfy.com/
    Quanjumps Team, HM, NZ.

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. What about my question about OOP programming? How does procedural code work with Ajax?

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you can do it procedurally. But it is like anything else, the procedural model breaks down at a certain level of complexity.

    Also, why mess around with the XMLHttpRequest object when there are several very capable frameworks that can handle the guts and let you concentrate on programming your application? I use CPAINT and it has really taken a lot of the pain out of the process.

  6. #6
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nemesis_256 View Post
    Is Ajax possible without OOP?
    Just do a google search for "Ajax tutorial" and you should find tons of tutorials that dont use OOP. Apple has a great tutorial, search for "apple xmlhttprequest" to find it.

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use the Jquery library and it has definitely simplified the whole Ajax thing so it feels procedural. There are lots of other good choices for Javascript libraries though so it depends on your preferences.

    Dave

  8. #8
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies. I have another question. In the code for this book, it requires you to have pop up blocking disabled for the ajax to work. What the heck is up with that? That's just not right.

  9. #9
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, that is not true.

  10. #10
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well in general, I know it's not true. But in the case of this book, it is. It has the following function:
    Code:
    this.handleErr = function() {
        var errorWin;
        // Create new window and display error
        try {
          errorWin = window.open('', 'errorWin');
          errorWin.document.body.innerHTML = this.responseText;
        }
        // If pop-up gets blocked, inform user
        catch(e) {
          alert('An error occurred, but the error message cannot be' +
          ' displayed because of your browser\'s pop-up blocker.\n' +
          'Please allow pop-ups from this Web site.');
        }
      }
    I just don't know why that's used, it destroys usability.

  11. #11
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So one question I have is, is Ajax possible without OOP? I'm not really talking about the XMLHttpRequest object, but instead of creating your own classes and methods, to simply do plain old functions.
    Of course.

    Another problem is that I'm still unclear as to what Ajax is. I understand that it uses the XMLHttpRequest object and changes content on pages without having to reload it. But can't this be done with plain old javascript timers?
    Ajax allows a webpage to communicate with the server behind the scenes. Without Ajax, a browser generally communicates with the server by requesting a page from the server, and when the server sends the requested page back, the browser loads the requested page.

    A js timer only delays some action from happening; it does not communicate with the server. js has always been used to change content on a web page. However, Ajax allows you to communicate with the server, obtain some data from the server, and then display that data on the page--without having to reload the page.

    Why is that beneficial? Because you may only want to update one number on a page, and therefore reloading the whole page is a waste of time.

    I just don't know why that's used, it destroys usability.
    Ajax itself destroys usability, so why not go all the way?

    I recently got the Ajax Sitepoint book, and I'm having problems with it
    I looked it over recently, and I too thought it was confusing.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •