Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Me1000

macrumors 68000
Original poster
Jul 15, 2006
1,794
4
So I have this simple ajax script to add entries to the DB, and it returns the result.

The serverside stuff works fine, and actually the AJAX part of it works in my desktop version of Safari! However when I open it on the iPhone, it doesn't do anything.

Can someone explain to me what the limitations of the iPhone are that prevents this from working and how I can fix it!

Thank You,


Code:
<script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
function ajaxFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!

		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('ajaxDiv');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var name = document.getElementById("name").value;
	var ip = document.getElementById("ip").value;
	var shout = document.getElementById("shout").value;
	var queryString = "?name=" + name + "&ip=" + ip + "&shout=" + shout;
	ajaxRequest.open("GET", "shouts_ajax_post.php" + queryString, true);
	ajaxRequest.send(null); 
}

//-->
</script>



<form name='myForm'>
<input type='text' id='name' value="Name" /> <br />
<input type='hidden' id='ip' value="<?= $_SERVER['REMOTE_ADDR'] ?>" />
<br />
<textarea id="shout" >Tap here to shout</textarea>
<input type='button' onclick='ajaxFunction()' value='Shout!' />
</form>

<div id='ajaxDiv'>Your result will display here</div>
 
Don't have an iphone so can't test my theories.. but i can think of two things that might cause it
  • Does the iPhone have "onclick" support on buttons? Can you make that action do anything else?
  • Try including the javascript form an external .js file (as inline javascript is always somewhat dubious in xhtml terms.
 
The iPhone uses the Safari web engine to display it's web content, and because the device doesn't allow downloading of plugins and such, AJAX and other rich web techniques are not only suggested, but required so the web site can function like an application.

One such company developers should look into for AJAX/iPhone integration is:

http://www.backbase.com/pages/iphone/

Check it out, folks.

-jim
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.