Ajax Jquery JavaScript

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 4

Ajax-Jquery vs JavaScript ( 721 lt xem )

i lc khi mi i n ranh gii ca lp trnh web 2.0 bn ang ng ng gia cc chc


nng ca n, cng nh bn bit rng web 2.0 th nn p dng ajax, tm hiu trn mng
hoc trong ti liu th bn hiu s s n l cch gi d liu khng ng b .

Nhng i vo vn khi n vi ajax bn thc s bi ri qu nhiu, khng bit c ch


hot ng, khng nm r n, v mt phn do vn ting anh yu m khng dm ng
chm n nhng cun sch JS ting anh

Mt thi gian no , c bn pm hi ti Anh i ! sao anh khng son tut dy Ajax,


em ton thy dy Jquery khng h. Khi c c vn ny, ti thc s b ng, ngi
ta c th hi mnh dy Ajax trong khi ngi ta bit Jquery. C bun ci khng khi hi
Anh i em bit s v Jquery nhng em m JS anh c th son tut JS cho em khng ?,
khi n li l vn khc.
tr li cho cu hi ny, bi vit hm nay s minh ha r rng v mi rng buc v
quan h gia Ajax, Jquery v JavaScript.
NH NGHA

Javascript : l mt ngn ng x l s kin thng thng cho website, thng thng


c dng s l cc s kin. Ngn ng cng theo cu trc chnh ca C, c th ni JS
ch khc PHP ngn ng, cn hng lp trnh th hu nh l ging nhau.
JQuery : Gn nh l mt m ngun m s dng JS, Jquery tng hp cc vn cn phi
lm trong JS thnh mt th vin, v sau n cho php pht biu theo cch gi ring ca
n.
Ajax : C th ni, Ajax ch l mt phn nh trong JSm khi thc hin theo JS thun Ajax
c th hin tng quan theo JS thun, khi th hin theo Jquery, cch s dng khc
nhau nhng mi tng quan ca n vi JS vn khng i, bi v bn thn n vn ch chy
trn JS.
PHN BIT

- Vi cch c th phn bit 3 dng ny, ta s i n gin t di ln trn.


Ajax : Ajax ch l mt hm nh nu bn s dng Jquery v l mt s kt hp nhiu thnh
phn nu bn s dng JS thun.
Ajax vi Jquery
view sourceprint?
01 $(document).ready(function(){
02
$.ajax({
//Ti y ta c th cho cc gi tr vo function Ajax, lc ny
03
Ajax l mt function.
04
url: 'leech_link.php',
05
type: 'POST',
06
dataType: 'html',
07
data: 'name='+varlue1+'&tuoi='+value2,
08
beforeSend(function(){
09
$('#wait').html('<img src='load.gif' title='' />);
10
}),
11
success(function(html){
12
$('#show').html(html);
13
})
14
});
15 });

- Ch vi vi dng nh th chng ta hon thnh mt ajax kh n gin, nhng bn cht


bn trong ca n khi tung tc vi JS th nh th no ? hay ni chnh xc hn, Ajax hot
ng trn JS th no, chng ta cng tham kho code sau :
Ajax vi JS thun
view sourceprint?
01 // Ajax function
02 function XMLHttpClient() {
03
var xmlhttp;
04
try {
05
// Mozilla / Safari / IE7
06
xmlhttp = new XMLHttpRequest();
07
} catch (e) {
08
// IE
09
var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0',
10
'MSXML2.XMLHTTP.4.0',
11
'MSXML2.XMLHTTP.3.0',
12
'MSXML2.XMLHTTP',
13
'Microsoft.XMLHTTP' );
14
var success = false;
15
for (var i=0;i < XMLHTTP_IDS.length && !success; i++) {
16
try {
17
xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

success = true;
} catch (e) {}
}
if (!success) {
throw new Error('Unable to create XMLHttpRequest.');
}
}
return xmlhttp;
}
function SetName(name)
{
var req =XMLHttpClient() ;
req.open('GET', 'setname.php?name=' + name, false);
req.send(null);
var newName =req.responseText;
alert(newName);
}

- Nh vy chng ta hiu r hn phn no Ajax, chng ta cng i qua vn tip theo


l Jquery
Jquery: Nh gii thch trn, bn thn Jquery cng ch l mt th vin tng hp hot
ng trn nn tng JS, chng minh iu ny, chng ta i vo mt v d nho nh, ti
mun ly gi tr ca mt ID no v cho hin th thng bo ra mn hnh.
S dng JS thun
view sourceprint?
1 //Nu bn mun ly gi tr ca n, bn phi s dng chui hm sau :
2
3
var myContent = document.getElementById('content');
4
alert(myContent.value);

v s dng Jquery
view sourceprint?
1 alert($('#content').val());

Ch n gin l vy m thi. Nh vy ci bn cn hiu, t mt phung thc no ,


Jquery c th thc thi cc lnh JS thng qua cch vit ca ring n, nhng thc s nn
tng n vn ch l JS.
JavaScript : Nh vy ti y, bi vit l kh tm n cho cc phn gii thch, v JS ti
khng c nhiu kin phn bit n, bi v n l nn tng cho s pht trin ca cc th
vin khc.

KT LUN

Nh vy gi chc bn mng tng c trong u, ci no nm u ? v v tr n


nh th no ri ng khng ?. Cng nh kho kin thc, kin thc l v hn, mt thut
ton s c nhiu cch gii, mt bi ton kh khng phi c kt qu l quan trng, m phi
lm sao cho n tn cng sc nht. Cng nh hc PHP, bn phi hc theo hng i
tng trnh i ti a nhng khai bo trng lp, trnh tt c nhng code khng cn
thit, nh Jquery vy, ngi ta gp chung n v t cho n mt cch khc gn gng hn

You might also like