Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parsing responseText

    Code:
    <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

  • #2
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Update

    Just wanted to make an update: I've figured it out...thought I would post the code for those who have similar issues.


    Code:
    <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>

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    That code should not run because of the Same Origin Policy.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •