Pages

Monday, January 17, 2011

JQuery XML parsing

<script type="text/javascript">
        $(document).ready(function () {
 
            $.each(($.browser), function (i, val) {
 
            });
 
            $("#btnlookup").click(function () { lookup(); });
 
 
        });
           if (!$.browser.msie) {
                alert('this utility is available only for IE, please try JSONP for other browsers');
                 return;
            }
            var addressURL = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + $("#txtAddress").val() + "&sensor=false";             alert(addressURL);             $("#output").text("");             $.ajax({                 url: addressURL,                 dataType: "xml",                 success: function (response) {                     if (!$.isXMLDoc(response)) {                         var outputStr = "Result is not valid XML Format";                         $(outputStr).appendTo($("#output"));                     }                     $.each($(response).find('result'), function () {                         var outputStr = "
" + "" + $(this).find('formatted_address').text() + " lat:" + $(this).find("location").find("lat").text() + ", lng" + +$(this).find("location").find("lng").text() + " " + "
"
;                         $(outputStr).appendTo($("#output"));                     });                 }, //sccess                 error: function (response) {                     var outputStr = "" + response.status + "";                     $(outputStr).appendTo($("#output"));                 }             }//ajax options                             );         }     script>

No comments:

Post a Comment