/ Published in: jQuery
Here is a basic example as to how to set up an Ajax request.
Expand |
Embed | Plain Text
<!-- jQuery Framework --> <script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript" charset="utf-8"> function getData( url ){ $.ajax({ url: url, dataType: "json", encoding:"UTF-8", beforeSend: ajaxStart, success: ajaxSuccess, error: ajaxError, complete: ajaxComplete }); } function ajaxStart( xhrInstance ){ //A. Clear Any Previously Written HTML //B. Show Preloader console.log( "ajaxStart:" ) } function ajaxError( xhrInstance, message, optional ){ console.log( "ajaxError:" ); } function ajaxComplete( xhrInstance, status ){ //A. Remove any preloaders console.log( "ajaxComplete:" ); } function ajaxSuccess( data, status ){ //Write your Parse XML Function parseData( data ); } function parseData( data ){ console.log( "parseData:", data ); } </script> <script type="text/javascript" charset="utf-8"> $(document).ready(function(){ getData("http://path/to/xml/or/json/feed"); } </script>
Comments
Subscribe to comments
You need to login to post a comment.

pretty extensive for a snippet, and quite handy. It is in the wrong section though :)
the whole site is snippets, no other sections
hdragomir,
This is pretty extensive but hey, once you master this, AJAX will prove to be a piece of pie. This code should be easy enough to re-purpose for JSON & Plain Text Requests.