Results 1 to 5 of 5

Thread: how exactly does ajax work?

  1. #1
    Join Date
    Jul 2009
    Location
    Binus University
    Posts
    472
    Thanks
    78
    Thanked 21 Times in 21 Posts

    Default how exactly does ajax work?

    Hi i just finish developing a website, i'm using ajax in some page.
    I don't have any problem in this web development, just want to know how ajax work.
    Here's a couple question about ajax:
    1. How ajax work? it load all the content at the begining or it load the content only when we call it?

    2. How ajax can screw up jquery? some jquery that i implement inside the ajax, don' work, so what happen with that?


    This is the web page that ajax content in it:
    http://www.kemangvillage.com/detail_ritz_5.php

    i put the ajax on overview, The Unique Feature, general specification button.

    Thx in advanced...
    _____________________

    David Demetrius // davejob
    _____________________

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    AJAX doesn't screw anything up. It does what it does, no more, no less. If you want to run scripts against the content AJAX pulls in, you can, after that content arrives. There are various strategies for doing so, jQuery can actually help with that. Most scripts on AJAX imported content will not run. You should only be pulling in markup anyway.

    You should not pull in stuff like a head or body, the page you are pulling to should already have those.

    It works pretty much the same way as the browser. It makes a request of the server and when the response comes it does something with the response.

    AJAX only fires when invoked, it doesn't get the stuff ahead of time, though you could make it do that if you wanted to.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2009
    Location
    Binus University
    Posts
    472
    Thanks
    78
    Thanked 21 Times in 21 Posts

    Default

    hmm, thank you very much John.

    So about this loading thing, page with ajax content don't load all the content when it start, it's just start when we trigger it right?

    How about Jquery, if ajax don't screw it up. are there any problem with position, what i mean is which one we must call first. You know when we put like this line code:
    Code:
    <!-- hover script start -->
    	<script src="script/hover/jquery.js"></script>
    	<link rel="stylesheet" type="text/css" href="script/hover/style.css">	
        <!--[if IE 7]>
            <link rel="stylesheet" type="text/css" href="script/hover/styleie.css">	
        <![endif]-->
    <!-- hover script end -->
    
    <!-- banner script start -->
    <link rel="stylesheet" type="text/css" href="script/banner/style.css" />
    <script type="text/javascript" src="script/banner/jquery.js"></script>
    <script type="text/javascript" src="script/banner/set.js"></script>
    <!-- banner script end -->
    why in some jquery we need to change the position, for example in that code, if we don't put the banner script at the top that page will screw up. So i need to put that code like this in <head>

    Code:
    <!-- banner script start -->
    <link rel="stylesheet" type="text/css" href="script/banner/style.css" />
    <script type="text/javascript" src="script/banner/jquery.js"></script>
    <script type="text/javascript" src="script/banner/set.js"></script>
    <!-- banner script end -->
    
    <!-- hover script start -->
    	<script src="script/hover/jquery.js"></script>
    	<link rel="stylesheet" type="text/css" href="script/hover/style.css">	
        <!--[if IE 7]>
            <link rel="stylesheet" type="text/css" href="script/hover/styleie.css">	
        <![endif]-->
    <!-- hover script end -->
    thank you
    _____________________

    David Demetrius // davejob
    _____________________

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The optimal order in which to place scripts on a page can depend upon a number of things. Sometimes though, it makes little or no difference. The fact that one script is jQuery and another is AJAX isn't so important as is what the scripts do. jQuery can do AJAX though. So if you're using jQuery anyway, you might want to get rid of any separate AJAX scripts and use the jQuery AJAX routines instead. Any decent script library can do AJAX, so that would apply to others as well. It's best to use only one library if possible.

    The particular reasons why any two or more scripts may interact in a subtle or not so subtle way isn't that they are AJAX or jQuery. It's just that they are two or more scripts. If really well written, it shouldn't matter what order, unless one depends upon having the other first for layout or other reasons, like one needing some code or calculation from the other script.

    Oh and sometimes just a small change to one script can allow it to go in a different order on the page than it could before.
    Last edited by jscheuer1; 12-13-2010 at 10:15 AM. Reason: add a little
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. The Following User Says Thank You to jscheuer1 For This Useful Post:

    davelf (12-13-2010)

  6. #5
    Join Date
    Jul 2009
    Location
    Binus University
    Posts
    472
    Thanks
    78
    Thanked 21 Times in 21 Posts

    Default

    thank you John, this is ajax & jquery thing is really confusing but it's interesting to learn.

    oh ya, i think you as the senior here need to make a sticky thread that explain what the differences between ajax, javascript, jquery. Cause all of them looks the same for a new coders.

    Thx
    _____________________

    David Demetrius // davejob
    _____________________

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
  •