Thread: Ajax in Safari
View Single Post
Old 12-16-2011, 09:02 PM   PM User | #3
Howard Rose
New to the CF scene

 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Howard Rose is an unknown quantity at this point
Unhappy The problem is with Safari.

Quote:
Originally Posted by cameron213 View Post
I am writing an application for the iphone that parses a weather feed based on gps location. I have the following which grabs coordinates based on a program called instamapper and posts them online. I am able to parse the necessary information and can print it to the screen in IE. However, as the iphone uses safari I want to see what my output is. How would I be able to do this? I've been running my code in an html file.

Code:
<html>
<script = "Javascript">



function fetchgps(callback)
{
      var url = "http://www.instamapper.com/api?action=getPositions&key=584014439054448247";
    
      var myRequest = new XMLHttpRequest();
      myRequest.onreadystatechange = function(e) {gps_xml_loaded(event, myRequest, callback);}
      myRequest.open("GET", url);
      myRequest.setRequestHeader("Cache-Control", "no-cache");
      myRequest.setRequestHeader("wx", "385");
      myRequest.send(null);
	   
     return myRequest;
}
	   
function gps_xml_loaded(event, this_request, callback)
{
    
     if (this_request.readyState == 4){
     
        if (this_request.status == 200) {
	
     	var obj = {error:false, errorString:null}

       var data = this_request.responseText;
	if (data == null) {callback(constructError("no <data>")); return;}

       collected=data.split(",");   //parses the data delimited by comma and put data into array
	   obj.latitude = collected[3];
	   obj.longitude = collected[4];
       callback(obj);
      }
    else
	  {
	    
		callback ({error:true, errorString:"Not Ready"}); //Could be any number of things..
	  }
    }
}

function dealwithgps(obj)
{
    if (obj.error == false){
     lat = obj.latitude;
     lon = obj.longitude;
     document.write("Latitude "+lat);
     document.write("Longitude "+lon); 
     }
     else{
     document.write("error detected");
     }
}

fetchgps(dealwithgps);





</script>
</html>
There is nothing (obvious) that is wrong with your code. The problem is is with Apple. There Safari browser does not support AJAX. I am current looking for a solution for myself. Hope you have better luck than I have had so far.

Hoppy
Howard Rose is offline   Reply With Quote