princerozario
Technical User
Hello
I am trying to receive a simple response through the help of javascript and XMLHttpRequest. It is not giving me a result. Could you tell where I have done it wrong.
When I ran the page it gave me an error message
"There was a problem with the request"
Here is the code. Thankyou
<html>
<head><title>Test XMLHttpRequest.. to XML</title></head>
<body>
<script type="text/javascript" language="javascript">
function makeRequest(url)
{
var http_request=false;
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()
{
alertContents(http_request);
}
http_request.open('GET', url, true);
http_request.send(null);
function alertContents(http_request)
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
alert(http_request.responseText);
} else
{
alert('There was a problem with the request');
}
}
}
}
</script>
<span
style="cursor: pointer; text-decoration: underline"
onclick="makeRequest('C:\Documents and Settings\Owner\My Documents\test.html')">
Make a request
</span>
</body>
</html>
I am trying to receive a simple response through the help of javascript and XMLHttpRequest. It is not giving me a result. Could you tell where I have done it wrong.
When I ran the page it gave me an error message
"There was a problem with the request"
Here is the code. Thankyou
<html>
<head><title>Test XMLHttpRequest.. to XML</title></head>
<body>
<script type="text/javascript" language="javascript">
function makeRequest(url)
{
var http_request=false;
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){}
}
if (!http_request){
alert('Giving up

return false;
}
http_request.onreadystatechange = function()
{
alertContents(http_request);
}
http_request.open('GET', url, true);
http_request.send(null);
function alertContents(http_request)
{
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
alert(http_request.responseText);
} else
{
alert('There was a problem with the request');
}
}
}
}
</script>
<span
style="cursor: pointer; text-decoration: underline"
onclick="makeRequest('C:\Documents and Settings\Owner\My Documents\test.html')">
Make a request
</span>
</body>
</html>