[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

how do I get the ajax XMLHTTP request to work in the Android browser?

Posted on 2010-03-31
3
Medium Priority
?
5,196 Views
Last Modified: 2013-12-07
I am trying to build a web application for the Android, but my XMLHTTP request does not work.  I currently have the web app working in Safari on the iPhone.  I have searched the internet extensively and found articles that say the Android browser does support the XMLhttp request and some that say it does Not work.  

Here is a good article: http://tetontech.wordpress.com/2009/02/27/android-webview-and-ajax/

What is the deal?  Is XMLHTTP supported or not?  Is there something special I have to do for the Android?   Can you give me an example of an XMLHTTP request working on the Android?

Thanks for the help!


This works in Mobile Safari, but not Android 2.0.1:

function getCurrentStatusBatch(){
      xhttp = new XMLHttpRequest();
      
      var batchReq = '<list is="obix:BatchIn">';
      //get current Thermostat Mode  (0=off, 1=Cool, 2=Heat, 3=Auto)   node=0
      batchReq += '<uri is="obix:Read" val="' + BaseURL + BasePoint + aptNum + '/Logic/SystemMode/out/" />';
      //get current Hold (0=no hold active, 1=hold active)    node=1
      batchReq += '<uri is="obix:Read" val="' + BaseURL + BasePoint + aptNum + '/Logic/Schedule/HoldType/out/" />';
      
      batchReq += '</list>';
      //xhttp.open("POST", "http://172.16.1.25/obix/batch", false, "admin");
      xhttp.open("POST", "/obix/batch", false, "admin");
      xhttp.send(batchReq);
      xmlDoc=xhttp.responseText;
      
      if (xmlDoc.length == 0){
      alert("nothing");
      }
      else{
      alert("somethin in there")}
      
      }
0
Comment
Question by:jfBLOOM22
  • 2
3 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 29390213
Hello jfBLOOM22,

Try the script in the code snippet, it work for me (I get a responseText) with Android 2.1 :

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
	window.onload = function() {
		var xmlhttp = null;
		if(window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

		if(xmlhttp == null) {
			alert("your browser don't support Ajax");
		}
		else {
//			alert("your browser support Ajax");
			xmlhttp.open("GET","simple.php",false);
			xmlhttp.send();
			alert( "responseText : " + xmlhttp.responseText );
		}
	}
</script>
</head>
<body>
</body>
</html>

Open in new window

0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 29390466
WebKit support CSS, Javascript, DOM and...AJAX

simple.php :


<?PHP
	echo "banana split";
        // Yep, very simple...
?>

Open in new window

0
 

Author Closing Comment

by:jfBLOOM22
ID: 32999265
The issue ended up being with the webserver.  We are using something called NiagaraAX to host the website, and for some reason it is responding to the xmlhttp request without the header information.  for whatever reason the Safari browser does not seem to mind, but the Palm and Android browsers think the document is empty.

The solutions helped me troubleshoot and narrow down the issue.  Thanks for the help?
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article summarizes the problem of addictive cell phone usage that college students across the country are facing. It covers the issues with obsessive cell phone addiction, reasons why this is happening, and what we can do to solve this problem.
Ready to kick start your career in 2018? Add app developer skills to your resume. January’s Course of the Month features Android App Development training with hands-on learning.  Read on to learn why these skills are important.
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

611 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question