Connecting Tech Pros Worldwide Forums | Help | Site Map

can't call the servlet using AJAX

sk
Guest
 
Posts: n/a
#1: Jul 18 '06
I create some javascript to send some search request.
However, on some machines i wont' be able to send
request. What could be the reason?

function sendSearchRequest()
{
var srch_url = "/servlet/Search";
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}

request.open('GET', srch_url , true );
request.onreadystatechange = GetSearchResponse;
request.send(null);
}

function GetSearchResponse()
{}



Randy Webb
Guest
 
Posts: n/a
#2: Jul 19 '06

re: can't call the servlet using AJAX


sk said the following on 7/18/2006 6:34 PM:
Quote:
I create some javascript to send some search request.
However, on some machines i wont' be able to send
request. What could be the reason?
Several.

The browser doesn't support the HTTPRequest Object.
The browser doesn't allow ActiveX.
You are using limited HTTPRequest code.
Quote:
function sendSearchRequest()
{
var srch_url = "/servlet/Search";
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
If the browser doesn't support Msml2.XMLHTTP or Microsoft.XMLHTTP then
your code fails silently. There are MSIE's with other versions of
XMLHTTP support and no non-IE browser supports your code.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Closed Thread