Wednesday 5 September 2012

jQuery Ajax Sending Request

Send data to the server, save some data to the server, and notify the user once it's complete. If the request fails, alert messge will display to user.

var request=$.ajax({
                url:'ajax_filter_search.php',
                data:'action=filterSearch&filterId='+filterId+'&restId='+restId,
                });
           
            // IF REQUEST IS DONE   
            request.done(function(result){
                setTimeout( function() {
                        $('#middlecontent').html(result);
                    }, 800 );   
                });
           
            // IF REQUEST IS FAIL   
            request.fail(function(jqXHR,textStatus) {
              alert( "Request failed: " + textStatus );
            });    

No comments:

Post a Comment