and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
This is my first trial to use ajax.
[syntax="javascript"]
function makeRequest(url,id_wanted) {
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
// See note below about this line
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Giving up Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = function() { GetData(http_request,id_wanted); };
http_request.open('GET', url, true);
http_request.send(null);
}
function GetData(http_request,id_wanted) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
/*HERE I GET THE DATA USING THE DOM Wont put that code here to make it more readable*/
//RESPONSE
}
} else {
alert('There was a problem with the request.');
}
}
}
When i call the makeReques() function i get the alert "There was a problem with the requst"
I have checked it out and the request status, aparently and obviously, is 404, and not 200. The readystate is 4 = ok
Do you have any idea why can that be?
What should i check?
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
http://msdn2.microsoft.com/en-us/library/ms534361.aspx wrote:0 (Uninitialized) The object has been created, but not initialized (the open method has not been called).
1 (Open) The object has been created, but the send method has not been called.
2 (Sent) The send method has been called, but the status and headers are not yet available.
3 (Receiving) Some data has been received. Calling the responseBody and responseText properties at this state to obtain partial results will return an error, because status and response headers are not fully available.
4 (Loaded) All the data has been received, and the complete data is available.
things work but i have another related issue now that i'd like to ask.
When i call the html page and make the ruquest to the server i get connected (status 200) and all is ok.
However if i make another request it fails, so i have to close my browser in order to be able to make a request. Its sound reasonable, i guess i have to close the previous connection. Is there any way to do that?
Will .abort() do the thing?
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
well i thought things were ok but not really...this is what i do. you can check this test on [url]http://www.houseonmap.gr/test2.html[/url]
[syntax="html"]<html>
<head>
<script language="javascript" type="text/javascript">
function getHTTPObject() {
if (typeof XMLHttpRequest != 'undefined') {
return new XMLHttpRequest();
}
try {
return new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {} } return false;
}
function makeRequest(id_wanted){
var url = "http://www.houseonmap.gr/areadata.xml";
var http_request = getHTTPObject();
http_request.open("GET", url, true);
http_request.onreadystatechange = function() {
document.form1.T5.value = "In here but ready state always undefined";
if(http_request.readystate == 0) {document.form1.T1.value = "0";}
if(http_request.readystate == 1) {document.form1.T1.value = "1";}
if(http_request.readystate == 2) {document.form1.T2.value = "2";}
if(http_request.readystate == 3) {document.form1.T3.value = "3";}
if(http_request.readystate == 4) {document.form1.T4.value = "4";}
}
http_request.send(null);
}
</script>
</head>
</body>
<form method="POST" name = "form1">
<p><input type="text" name="T1" size="40"></p>
<p><input type="text" name="T2" size="40"></p>
<p><input type="text" name="T3" size="40"></p>
<p><input type="text" name="T4" size="40"></p>
<p><input type="text" name="T5" size="40"></p>
</form>
<p>
<select size="1" name="Area" onchange = "javascript: makeRequest(this.value)">
<option value="1" selected>Selection1</option>
<option value="2">Selection2</option>
<option value="3">Selection3</option>
</select></p>
</p>
</body>
</html>
It seems as the state of the http_request changes, as the fucntion is called, but the values is neither 0,1,2,3 or 4
Can you find out why is that?
thanks and merry christmas
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]