You need to make an asynchronous request. The third parameter of the open method should be true.
Problem with XMLHttpRequest in java script
Collapse
X
-
still no joy but many thnks for offering to look at the files...
i have test.asp....... ............... ............... ............... ............... ............... ....
[HTML]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<script language="javas cript" src="test.js"></script>
<input type="button" value="test me" onclick="testMe ()">
</body>
</html>
[/HTML]
then testReturn.asp. ............... ............... ............... ............... ............... ..........
[HTML]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
hello
</body>
</html>
[/HTML]
and finally test.js........ ............... ............... ............... ............... ............... ...
[CODE=javascript]function testMe() {
var dupeText = "";
var xmlHttpReq=fals e;
var strURL = "http://localhost/cdvr/dev/testReturn.asp"
if (!window.Active XObject) {
alert("Firefox" );
xmlHttpReq = new XMLHttpRequest( );
} else {
alert("Microsof t");
xmlHttpReq = new ActiveXObject(" Microsoft.XMLHT TP");
}
xmlHttpReq.open ('POST',strURL, true);
xmlHttpReq.setR equestHeader('C ontent-Type','applicat ion/x-www-form-urlencoded');
xmlHttpReq.onre adystatechange = function() {
if (xmlHttpReq.rea dyState == 4) { //ready state 4 means its complete.
dupeText = xmlHttpReq.resp onseText;
alert ("dupeText=" + dupeText);
}
}
xmlHttpReq.send ();
}[/CODE]Comment
-
at last !!!!!
i had to change
xmlHttpReq.send (data);
to
var data=""
xmlHttpReq.send (data);
as i finally figured out ff was throwing this error...
Error: uncaught exception: [Exception... "Not enough arguments" nsresult: "0x80570001 (NS_ERROR_XPC_N OT_ENOUGH_ARGS) " location: "JS frame :: http://localhost/cdvr/dev/test.js :: testMe :: line 25" data: no]
Thanks for all your help, i really appreciate it, i'm going out to celebrate...... .!Comment
-
ok but have a js function call like this
[CODE=javascript]var answer = checkDupeDate()
alert ("answer=" + answer);
function checkDupeDate() {
.......
xmlHttpReq.open ('POST',strURL, true);
xmlHttpReq.setR equestHeader('C ontent-Type','applicat ion/x-www-form-urlencoded');
xmlHttpReq.onre adystatechange = function() {
if (xmlHttpReq.rea dyState == 4) { //ready state 4 means its complete.
dupeText = xmlHttpReq.resp onseText;
alert (" firefox dupeText 1 = " + dupeText);
return dupeText;
}
}
xmlHttpReq.send (params);
}
[/CODE]
Now when i call checkDupeDate it always returns nothing as it isn't waiting for the xmlHttpReq to do it's thing. i get
firstly alert(answer) which is blank
then alert (" firefox dupeText 1 = " + dupeText) which sites on top of the first alertComment
Comment