The jQuery.getJSON( url, [data], [callback] ) method loads JSON data from the server using a GET HTTP request.
Mentioned in that post is the idea that the likes $.getJSON (), $.get () and $.post () covered here are global functions / methods and therefore you do not attach them to a selector as we often do with other jQuery methods. It is true, there is currently no $.postJSON()method, but you can accomplish the same thing by specifying a fourth parameter (type) in the $.post()function: My code looked like this: $.post('script.php', data, function(response) { // Do something with the request}, 'json'); $.getJSON is performing a http get under the covers. So post() method will automatically parse response into JSON object. The jQuery.getJSON() Ajax method, allows us to load data from the server, that has been JSON encoded, using a HTTP GET request.. Shorthand version $.getJSON(). Syntax: $(selector).getJSON(url,data,success(data,status,xhr)) Parameters: This method accepts three parameters as mentioned above and described below: url: It is required parameter. Browsers operate the 'same origin policy', which means a request can not successfully retrieve data from a … Alas, the jQuery documentation lacks a sister function that should be named $.postJSON().Why not just use $.getJSON() and be done with it? The Promise interface in jQuery 1.5 also allows jQuery's Ajax methods, including $.getJSON (), to chain multiple .done (), .always (), and .fail () callbacks on a single request, and even to assign these callbacks after the request may have completed. Hope this helps. Here is the simple syntax to use this method − $.getJSON( url, [data], [callback] ) Parameters. I think I'm not alone too need a getJSON which passes datas via POST, so I did this little extend: jQuery.extend({ postJSON: function( url, data, callback) CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100 Try posting to the controller. You can also attach fail and done callback methods to post() method as shown below. Visit james.padolsey.com/jqueryand search for post() method to see the jQuery source code. Another quick note before we dive into some examples, $.getJSON (), $.get () and $.post () are all shorthand variants of the grandaddy jQuery AJAX method called er $.ajax.
Thanks you Tal very much for you response. Here is a function ( blog reference) that will provide the same functionality:
jQuery, communication AJAX data : les paramètres éventuels à envoyer (utilise alors la méthode POST) ... jQuery.getJSON(). If you only mark the last that gave you clarification because you misread an earlier post others will be confused. Your controller endpoint is expecting a post and will not accept a http get. Rest of the parameters are same as first example. jQuery getJSON() Method jQuery AJAX Methods. This jQuery XHR object, or "jqXHR," returned by $.post() implements the Promise interface, giving it all the properties, methods, and behavior of a Promise (see Deferred object for more information). With Regards, Krunal Parekh. Description. 1. Here is the description of all the parameters used by this method − If the request is already complete, the callback is …