Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Last active December 20, 2015 04:08
Show Gist options
  • Save PatrickJS/6068179 to your computer and use it in GitHub Desktop.
Save PatrickJS/6068179 to your computer and use it in GitHub Desktop.
Caching Ajax Request
;(function() {
var api = {},
$response = $('#response');
$('#ajaxForm').on('submit', function(e) {
e.preventDefault();
var search = $('#title').val();
$response.empty().addClass('loading');
if (!api[search]) {
api[search] = $.ajax({
url: 'http://api/jquery/jsonp/',
dataType: 'jsonp',
data: {
title: search
},
timeout: 15000
});
}
api[search].done(successFn).fail(errorFn).always(completeFn);
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment