10/10/2018, 00:11
Mới viết ajax, giúp tớ với.....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script type="text/javascript">
function xemds() {
var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest(); }
catch (e)
{ // Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) {
alert("Your browser does not support AJAX!");
return false; }
}
}
xmlHttp.onreadystatechange = process() {
var txt =';
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
response = xmlHttp.respon******ML.documentElement;
HS = response.getElementsByTagName('hocsinh');
for (var i=0; i<hs.length; i++)
{
txt='<strong>'+response.getElementsByTagName('hote n')[i].firstChild.data+'</strong><br>';
txt+='<strong>Ng� y sinh: </strong>'+response.getElementsByTagName('ngaysinh')[i].firstChild.data+'<br>';
txt+=response.getElementsByTagName('diachi')[i].firstChild.data;
document.write(txt);
}
}
else document.write('There was a problem: '+xmlHttp.statusText);
}
}
xmlHttp.open("GET","ds.xml",true);
xmlHttp.send();
}
</script>
<body>
<a href="#" onclick="xemds()">Xem danh sách há»c sinh</a>
</body>
</html>
================================================== ====================
Tớ chạy đoạn này mà kô đc.
Báo lỗi dòng 25 Expected ';' , dòng 49 Object Expected.
[=========> Bổ sung bài viết <=========]
http://users6.nofeehost.com/banhbao/tt.asp
Máy nhà hỏng rồi nên Tớ up lên host chạy.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<script type="text/javascript">
function xemds() {
var xmlHttp;
try
{ // Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest(); }
catch (e)
{ // Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) {
alert("Your browser does not support AJAX!");
return false; }
}
}
xmlHttp.onreadystatechange = process() {
var txt =';
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
response = xmlHttp.respon******ML.documentElement;
HS = response.getElementsByTagName('hocsinh');
for (var i=0; i<hs.length; i++)
{
txt='<strong>'+response.getElementsByTagName('hote n')[i].firstChild.data+'</strong><br>';
txt+='<strong>Ng� y sinh: </strong>'+response.getElementsByTagName('ngaysinh')[i].firstChild.data+'<br>';
txt+=response.getElementsByTagName('diachi')[i].firstChild.data;
document.write(txt);
}
}
else document.write('There was a problem: '+xmlHttp.statusText);
}
}
xmlHttp.open("GET","ds.xml",true);
xmlHttp.send();
}
</script>
<body>
<a href="#" onclick="xemds()">Xem danh sách há»c sinh</a>
</body>
</html>
================================================== ====================
Tớ chạy đoạn này mà kô đc.
Báo lỗi dòng 25 Expected ';' , dòng 49 Object Expected.
[=========> Bổ sung bài viết <=========]
http://users6.nofeehost.com/banhbao/tt.asp
Máy nhà hỏng rồi nên Tớ up lên host chạy.
Bài liên quan
bạn có thể dùng prototype hay jquery để viết
mình thấy trên mạng có prototype + smarty để làm ứng dụng smarty ajax bạn tìm trên mạng có đó nếu không tìm được liên hệ với mình: shinichi$herofit.net mình gửi cho
=====================
Cái readyState mà nó = 0,1,2,3 thì sao nhỉ?
Kiếm trong mấy cái code sẵn, toàn readyState=4.
0 : chưa được initialize
1 : vừa đựoc thiết lập
2 : vừa mới đựợc gửi đi
3 : đang trong quá trình xử lí
4 : hoàn tất, kèm theo responseText
Tức là lúc đang truy vấn tới máy chủ rồi lấy thông tin về, trong khoảng đó làm sao để nói cho người dùng bít là "Đợi tí xíu đi, sắp xong rùi"
[=========> Bổ sung bài viết <=========]
Tớ viết lại đoạn code ở trên http://users6.nofeehost.com/banhbao/tt.asp
Nhưng mà chạy, chỉ ra mỗi chữ "Loading......" hjx >_<
<html>
<head>
<title>effect</title>
</head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="eff.js"></script>
<body>
<div id="dotdotdot"></div>
</body>
</html>
// configuration
var dot = '. . . . . . . . . . . . . . . . .';
var speed = 50; // miliseconds
var j = 1; // posision
// on ready
$(document).ready(function () { dotdotdot(); })
// function effect
function dotdotdot ()
{
if ( j == dot.length) { j = 1; }
var show = dot.substr(0,j);
// show on html codes
$('#dotdotdot').html(show).show();
j++;
setTimeout('dotdotdot()', speed);
}