在一個巨大的web應用程序中,我需要一個提交表單的解決方法。覆蓋javascript標準提交函數行爲
爲了覆蓋內置的javscript方法,我嘗試了this example,但我甚至沒有彈出警報。
我對覆蓋提交功能的想法是這樣的:
function submit(event) {
var target = event ? event.target : this;
$.ajax({
url: target.action,
data: $('form').serialize(), // &nd someone knows how I can get the serialize() of the form I just clicked?
success: function (data) {
alert('done');
},
error: function (data) {
alert('error (check console log)');
console.log(data);
}
});
//this._submit();
return false;
}
到處使用的提交的方式是不相符的。原始代碼中的可能性:
<button onclick="form.submit">
onclick="calltoFunction();" // where inside the function the submit is called
<button type="submit" // the normal way
我想我的想法是可能的,因爲我之前覆蓋了js-functions。但是,我應該如何使用提交部分來完成。 歡迎任何建議,想法和修復!
你在ajax函數中沒有** type ** attr! – Jai
我確實在ajaxsetup中。對不起,不提。也試着把它放在函數中,沒有結果。 – user1469734