PDA

View Full Version : how exactly does ajax work?



davelf
12-13-2010, 07:22 AM
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...

jscheuer1
12-13-2010, 07:47 AM
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.

davelf
12-13-2010, 08:25 AM
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:


<!-- 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>



<!-- 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

jscheuer1
12-13-2010, 10:09 AM
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.

davelf
12-13-2010, 10:35 AM
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:)