How to access a non-local URL in Javascript
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nicholas_Gillotte
Posted On:   Tuesday, December 12, 2006 09:01 AM

Untitled Document I am having trouble with a basic AJAX program. I am trying to send a GET request via Javascript, but nothing seems to happen (the server doesn't react to receiving the request). I know the server works; I can recieve the GET response by pointing a browser at it. Here is my webpage: Test And here is my js function: function onTest() { var xmlhttp=false; var url = "http://localhost:8080/wag/login"; if (!xmlhttp && typeof XMLHttpRequest!='undefined') { try { xmlhttp = new XMLHttpRequest(); }   More>>
Untitled Document

I am having trouble with a basic AJAX program. I am trying to send a GET request via Javascript, but nothing seems to happen (the server doesn't react to receiving the request). I know the server works; I can recieve the GET response by pointing a browser at it.


Here is my webpage:


			








Test





And here is my js function:


			
function onTest()
{
var xmlhttp=false;
var url = "http://localhost:8080/wag/login";
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false;
}
}
if (!xmlhttp && window.createRequest) {
try {
xmlhttp = window.createRequest();
} catch (e) {
xmlhttp=false;
}
}

xmlhttp.open("GET", url, false);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
if (xmlhttp.status==200) alert("URL Exists!")
else if (xmlhttp.status==404) alert("URL doesn't exist!")
else alert("Status is " + xmlhttp.status)
alert(xmlhttp.responseText);
}
}
xmlhttp.send(null)
}


When I click the button on my webpage, nothing happens. Does anyone see any reasons why this wouldn't work? Thanks in advance for anyone that can help.

   <<Less

Re: How to access a non-local URL in Javascript

Posted By:   Firat_Tiryaki  
Posted On:   Tuesday, December 12, 2006 09:48 AM

I think there is something wrong with your xmlhttp variable, A variant confliction maybe...


Try to use below function to create your xmlhttp object, it will work fine



function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

xmlhttp=GetXmlHttpObject();
About | Sitemap | Contact