-
-
Save kattrali/3004803 to your computer and use it in GitHub Desktop.
Ajax and jquery get request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// target request: | |
// http://nominatim.openstreetmap.org/reverse?format=xml&lat=40.004&lon=-82.862&MaxResponse=1&zoom=17&accept-language=en-us&addressdetails=1 | |
var getMyData = (function() { | |
var lat = document.forms[0].lat.value; | |
var lng = document.forms[0].lon.value; | |
return {format:"xml",lat:lat,lng:lng,MaxResponse:1,zoom:17,"accept-language":"en-us",addressdetails:1}; | |
}) | |
var submitForm = function() { | |
var myURL = "http://nominatim.openstreetmap.org/reverse"; | |
$("#docs").appendChild("<p>"+myURL+"</p>"); | |
$.ajax({ | |
dataType: "xml", | |
url: myURL, | |
type: "GET", | |
data: getMyData(), | |
mimeType: "xml", | |
success: function(data,textStatus, jqXHR) { | |
alert("1"); | |
var xmlData = data, | |
xmlDoc = $.parseXML(xmlData), | |
$xml = $( xmlDoc ), | |
$result = $xml.find( "road"); | |
alert( $xml.text() ); | |
$( "#docs" ).append( $result.text() ); | |
}, | |
error:function(response) { | |
alert("An error occurred while communicating with the OpenLS service. Please try again."); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment