...

View Full Version : Parsing responseText



cameron213
08-20-2010, 02:35 AM
<html>
<script = "Javascript">
window.onload = function(){

var myRequst = new XMLHttpRequest();

var url = "http://www.instamapper.com/api?action=getPositions&key=584014439054448247";

myRequst.open('get', url);

myRequst.onreadystatechange = function(){

if ((myRequst.readyState == 4) && (myRequst.status == 200)){

alert(myRequst.responseText);

}

}

myRequst.send(null);


}

</script>
</html>


What I am trying to do is parse the responseText data that is returned in the alert window. I know you cant parse it from here, but this was my way of seeing what was returned. I know that I should be able to use string.split methods. The returned data is delimited by commas, and I only need two values from it. A longitude and latitude value. I have no problem setting up a parser for xml formatted data, but not quite sure how I access the data in this case. Thanks for the suggestions

cameron213
08-20-2010, 03:10 AM
Just wanted to make an update: I've figured it out...thought I would post the code for those who have similar issues.





<html>
<script = "Javascript">
window.onload = function(){

var myRequest = new XMLHttpRequest();

var url = "http://www.instamapper.com/api?action=getPositions&key=584014439054448247";

myRequest.open('get', url);

myRequest.onreadystatechange = function(){

if ((myRequest.readyState == 4) && (myRequest.status == 200)){


var data = myRequest.responseText;
collected=data.split(","); //parses the data delimited by comma and put data into array

document.write("4: Latitude "+collected[4]+"<BR>\n"); //display elementy of array
document.write("4: Longitude "+collected[5]+"<BR>\n");

}

}

myRequest.send(null);


}

</script>
</html>

A1ien51
08-27-2010, 09:05 PM
That code should not run because of the Same Origin Policy. (http://codingforums.com/newreply.php?do=newreply&noquote=1&p=985208)

Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum