|
xmlhttprequest readystate
|
|
|
| |
Реклама / Advertisment
|
| |
Википедия
...
|
| |
Ссылки
|
|
|
| |
Блоги
http://www.cmsno.info/html/7469.html ASP设计博客教程(六) (by: admin) 服务器在完成请求之后会在<b>xmlhttprequest</b> 的onreadystatechange 属性中查找要调用的方法。在ajax 应用程序中需要了解五种就绪状态:. a:0请求没有发出(在调用open() 之
http://clamor.tistory.com/77 XHR 객체 생성과 메소드 (by: ™ 때려 콜백함수는 <b>readyState</b> 값이 변할때마다 호출 u003du003du0026gt; 된다. 요청이 서버로 보내지면 <b>readyState</b> 는 5가지 숫자값으로 계속 변화가 일어난다 <b>readyState</b> u003du003du0026gt; 요4
|
| |
Видео
|
|
|
| |
Загрузки
|
| |
Определение
No definitions found for xmlhttprequest readystate.<br /><hr width="80%" />
|
| |
Вопросы и ответы
ajax readystate issues? req = new XMLHttpRequest();
req.onreadystatechange = processReqChange(what);
req.open('POST', url, true);
function processReqChange(what) {
alert(req.readyState); <------------------------COMING OUT TO BE 0
// only if req shows 'loaded'
if (req.readyState == 4) {
// only if 'OK'
if (req.status == 200) {
alert(what);
eval(what);
} else {
alert('There was a problem retrieving the XML data: ' +
req.responseText);
}
}
}
new to ajax? it looks like a rookie mistake,
the state change function is called many tmes... and the first time the state may be zero!
you should ignore just about anything but a 4/200.
not sure what you expect with what, but it's probably not what you want!
a full ajax request needs a lot more code, to make it work cross platform and cross browser. A LOT of painful, annoying code that will change every few years (or months). By using an established library, you will be prepared for the tricks that browser makers can throw at us!
I use http://jquery.com , and ajax is a breeze!
Using XMLHTTPRequest in javascript to verify if URL is working? I want to verify if a link is working before I display some content in the iframe. I used XMLHttpRequest to open the page and check the status.
The function gives error ‘access is denied when run locally, hence I hosted the same on some webserver.
Here the event onreadystatechange is never executed. I tried both sync and async open. Any inputs on how to resolve this will be useful.
<<CODE SNIPPET START>>
var urlObj = null;
if ( window.XMLHttpRequest ) {
urlObj = new window.XMLHttpRequest();
}
urlObj.open( "HEAD", strUrl, true ); // true = async, false = sync
urlObj.onreadystatechange = function()
{
alert(urlObj.readyState);
if ( urlObj.readyState == 4 ) {
if (( urlObj.status == 200 ) { alert( "Server replied OK" ); }
else { alert( "There was a problem: " + urlObj.status ); }
}
}
<<CODE SNIPPET END>>
Thanks & Regards,
Chandra
your problem is that you wrote all that code without knowing that ajax has a security model makes it impossible to reference a foreign hosted http object.
strUrl is pointing somewhere you can't get to!
and you got a state/status error that tells you so.
Why the Ajax code below in ajax.js is causing my form not to work ? ajax.js:
Code: ( text )
1.
var a=0;
2.
var b=0;
3.
var c=0;
4.
var d=0;
5.
var e=0;
6.
var f=0;
7.
8.
function check1()
9.
{
10.
if (document.getElementById("text1").value == "")
11.
{
12.
a=0;
13.
document.getElementById("alert1").style.visibility="visible";
14.
}
15.
else
16.
{
17.
a=1;
18.
document.getElementById("alert1").style.visibility="hidden";
19.
}
20.
}
21.
22.
function check2()
23.
{
24.
if (document.getElementById("text2").value == "")
25.
{
26.
b=0;
27.
document.getElementById("alert2").style.visibility="visible"
28.
}
29.
else
30.
{
31.
b=1;
32.
document.getElementById("alert2").style.visibility="hidden";
33.
}
34.
}
35.
36.
function check3()
37.
{
38.
if (document.getElementById('text3').value == "")
39.
{
40.
document.getElementById("alert3").style.visibility="visible";
41.
c=0;
42.
}
43.
else
44.
{
45.
document.getElementById("alert3").style.visibility="visible";
46.
c=1;
47.
}
48.
}
49.
50.
function check4()
51.
{
52.
if (document.getElementById('text4').value == "")
53.
{
54.
document.getElementById("alert4").style.visibility="visible";
55.
d=0;
56.
}
57.
else
58.
{
59.
document.getElementById("alert4").style.visibility="hidden";
60.
d=1;
61.
}
62.
}
63.
64.
function check5()
65.
{
66.
if (document.getElementById('text5').value == "")
67.
{
68.
document.getElementById("alert5").style.visibility="visible";
69.
e=0;
70.
}
71.
else
72.
{
73.
document.getElementById("alert5").style.visibility="hidden";
74.
e=1;
75.
}
76.
}
77.
78.
function check6()
79.
{
80.
if (document.getElementById('text6').value == "")
81.
{
82.
document.getElementById("alert6").style.visibility="visible";
83.
f=0;
84.
}
85.
else
86.
{
87.
if (document.getElementById('text6').value==document. getElementById('text5').value)
88.
{
89.
document.getElementById("alert6b").style.visibility="hidden";
90.
f=1;
91.
}
92.
else
93.
{
94.
document.getElementById("alert6b").style.visibility="visible";
95.
f=-1;
96.
}
97.
}
98.
}
99.
100.
var xmlHttp;
101.
var xmlHttp2;
102.
103.
function GetXmlHttpObject()
104.
{
105.
var xmlHttp=null;
106.
var xmlHttp2=null;
107.
try
108.
{
109.
// Firefox, Opera 8.0+, Safari
110.
xmlHttp=new XMLHttpRequest();
111.
xmlHttp2=new XMLHttpRequest();
112.
}
113.
catch (e)
114.
{
115.
// Internet Explorer
116.
try
117.
{
118.
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
119.
xmlHttp2=new ActiveXObject("Msxml2.XMLHTTP");
120.
}
121.
catch (e)
122.
{
123.
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
124.
xmlHttp2=new ActiveXObject("Microsoft.XMLHTTP");
125.
}
126.
}
127.
return xmlHttp;
128.
return xmlHttp2;
129.
}
130.
131.
function checkUsername(str)
132.
{
133.
if (str.length==0)
134.
{
135.
document.getElementById("alert4").style.visibility="visible";
136.
return;
137.
}
138.
else
139.
{
140.
document.getElementById("alert4").style.visibility="hidden";
141.
xmlHttp=GetXmlHttpObject()
142.
if (xmlHttp==null)
143.
{
144.
alert ("Your browser does not support AJAX!");
145.
return;
146.
}
147.
var url="username.php";
148.
url=url+"?q="+str;
149.
url=url+"&sid="+Math.random();
150.
xmlHttp.onreadystatechange=stateChanged();
151.
xmlHttp.open("GET",url,true);
152.
xmlHttp.send(null);
153.
}
154.
}
155.
156.
function stateChanged()
157.
{
158.
if (xmlHttp.readyState==4)
159.
{
160.
document.getElementById("alertuse").innerHTML=xmlHttp.responseText;
161.
}
162.
}
163.
164.
function signup(stra, strb, strc, strd, stre)
165.
{
166.
xmlHttp2=GetXmlHttpObject()
167.
if (xmlHttp2==null)
168.
{
169.
alert ("Your browser does not support AJAX!");
170.
return;
171.
}
172.
var url2="signingup.php";
173.
url2=url2+"?a="+stra+"?b="+strb+"?c="+strc+"?d="+strd+"?e="+stre"?f="+a+"?g="+b+"?h="+c+"?i="+d+"?f="+e;
174.
xmlHttp2.onreadystatechange=stateChanged2;
175.
xmlHttp2.open("GET",url2,true);
176.
xmlHttp2.send(null);
177.
}
178.
179.
function stateChanged2()
180.
{
181.
if (xmlHttp2.readyState==4)
182.
{
183.
document.getElementById("www").innerHTML=xmlHttp2.responseText;
184.
}
185.
}
this is the form:
Code: ( text )
1.
<html>
2.
<head>
3.
<title></title>
4.
<script src="ajax.js" type="text/javascript"></script>
5.
</head>
6.
<body>
7.
<label for=first id=first>First Name :</label> <input type="text" id="text1" onchange="check1();" />
8.
<span id="alert1" style='visibility:hidden;'><< Please fill your first name in this field.</span><br><br>
9.
10.
<label for=last id=last>Last Name :</label> <input type="text" id="text2" onfocus="check1();" onchange="check2();" />
11.
<span id="alert2" style='visibility:hidden'><< Please fill your last name in this field.</span><br><br>
12.
13.
<label for=email id=email>E-mail :</label> <input type="text" id="text3" onfocus="check1(), check2();" onchange="check3();" />
14.
<span id="alert3" style='visibility:hidden'><< Please fill your email in this field.</span><span id="alert3b" style='visibility:hidden'><< Your email ain't valid. Please enter a valid e-mail.</span><br><br>
15.
16.
<label for=username id=username>Username :</label> <input type="text" id="text4" onfocus="check1(), check2(), check3();" />
17.
<span id="alert4" style='visibility:hidden'><< Please fill your desired username in this field.</span>
18.
<span id="alert4b" style='visibility:hidden'><< Username taken. Please choose another username.</span><br><br>
19.
20.
<label for=pass id=pass>Password :</label> <input type="password" id="text5" onfocus="check1(), check2(), check3(), checkUsername(document.getElementById('text4').val ue);" onchange="check5();" />
21.
<span id="alert5" style='visibility:hidden'><< Please fill your desired password in this field.</span><br><br>
22.
23.
<label for=cpass id=cpass>Confirm Password :</label> <input type="password" id="text6" onfocus="check1(), check2(), check3(), check4(), check5();" /><span id="alert6a" style='visibility:hidden'><< Please confirm your password.</span><span id="alert6b" style='visibility:hidden'><< Passwords don't match.</span><br><br>
24.
<span id=alertuse></span> <span id=www></span>
25.
<input type="submit" name="signup" value="Sign Up" onmouseover="signup(document.getElementById('text1').value, document.getElementById('text2').value, document.getElementById('text3').value, document.getElementById('text4').value, document.getElementById('text6').value);" />
26.
27.
28.
<div id=confirm style='visibility:hidden;'>
29.
Please enter the confirmation code in the box below.<br><br>
30.
Confirmation Code: <input type="text" name="ccode" /> <input type="button" value="Confirm" onclick=''/>
31.
</div>
32.
33.
</body>
34.
</html>
pls help..
Thanks for making my morning!
You can't past the entire page here and expect someone to re-construct the page!
put up a live link...then every hacker and his sister will try it out for you!
|
|