article

Saturday, August 23, 2014

The Perfect AJAX Request

The Perfect AJAX Request

$.ajax({
  type: 'POST',
  url: 'http://tutorial101.blogspot.com/feed/',
  data: { postVar1: 'theValue1', postVar2: 'theValue2' },
  beforeSend:function(){
    // this is where we append a loading image
    $('#ajax-panel').html('
Loading...
'); }, success:function(data){ // successful request; do something with the data $('#ajax-panel').empty(); $(data).find('item').each(function(i){ $('#ajax-panel').append('

' + $(this).find('title').text() + '

' + $(this).find('link').text() + '

'); }); }, error:function(){ // failed request; give feedback to user $('#ajax-panel').html('

Oops! Try that again in a few moments.

'); } });

Related Post