What is the problem here? (Besides having redundant code). $.getJSON
works as expected. However $.postJSON
isn't working. I can inspect $.fn
via firebug and sure enough postJSON is listed. However if I try to call it, I get a no function defined error.
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);
};