$.ajax({ type: 'GET', // GET is the default but I like to specify it url: 'http://example.com/mything.php', // Put your URL here dataType: 'json', cache: false, // Stops the browser from caching, $.get() doesn't do this success: function(data) { // Do something with data }, error: function(jqXHR, textStatus, errorThrown) { // $.get() doesn't do this either. You need to handle errors alert('Error ' + textStatus + ' ' + errorThrown); // Or console.log() }, });
Programming Tips - jQuery: reliably get some JSON from a server
Date: 2014nov23
Library: jQuery
Language: javaScript
Q. jQuery: reliably get some JSON from a server
A. jQuery has $.get() but its not good enough. Any production
code needs to use $.ajax() like this: