jQuery $.ajax() jsonp timeout performormance

Benchmark created by Binyaminn on


Description

jQuery $.ajax() jsonp timeout performormance

Preparation HTML

<div id=content></div>
<script src=//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js></script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery $.ajax() timeout
$.ajax({
 type: "GET",
 url: '//jsperf.com/api/jsonp',
 dataType: 'jsonp',
 timeout: 1000,
 success: function(data) {
  $('#content').html(data.content);
 },
 error: errorHandler
});

function errorHandler(jqXHR, status, error) {
 if (status == 'timeout') {
  $('#content').html('Still loading...');
 } else {
  $('#content').html('404 Not found');
 }
};
ready
window.setTimeout()
var timer = window.setTimeout(function() {
 $('#content').html('Still loading...');
}, 1000);
$.ajax({
 type: "GET",
 url: '//jsperf.com/api/jsonp',
 dataType: 'jsonp',
 success: function(data) {
  window.clearTimeout(timer);
  $('#content').html(data.content);
 },
 error: function() {
  window.clearTimeout(timer);
  $('#content').html('404 Not found');
 }
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.