1
ここで問題は何ですか? (冗長コードを持つ以外に) $.getJSON
は期待どおりに動作します。しかし、$.postJSON
は機能しません。 firebugで$.fn
を調べることができ、十分なpostJSONが表示されていることを確認できます。しかし、私がそれを呼び出そうとすると、関数定義エラーが返されます。jQuery.fn - なぜこれは機能しませんか?
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);
};