Quel est le problème ici? (En plus d'avoir un code redondant). $.getJSON
fonctionne comme prévu. Cependant $.postJSON
ne fonctionne pas. Je peux inspecter $.fn
via firebug et bien sûr, postJSON est listé. Cependant si j'essaye de l'appeler, j'obtiens une erreur définie sans fonction.jQuery.fn - Pourquoi ça ne marche pas?
jQuery.fn.getJSON = function(path, opts){
this.extend(opts, {
url: path,
dataType: 'json',
type: 'GET'
});
var invalid = opts.error;
opts.error = function(xhr, status){
var data = $.httpData(xhr, 'json');
if (invalid)
invalid(data);
}
this.ajax(opts);
};
jQuery.fn.postJSON = function(path, data, opts) {
this.extend(opts, {
url: path,
data: data,
dataType: 'json',
type: 'POST'
});
var invalid = opts.error;
opts.error = function(xhr, status){
var data = $.httpData(xhr, 'json');
if (invalid)
invalid(data);
}
this.ajax(opts);
};