Ajax simple, first trial not working...help?
Posted: Wed Dec 20, 2006 10:40 pm
feyd | Please use
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?
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
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.');
}
}
}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?
feyd | Please use[/syntax]
Code: Select all
,Code: Select all
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]