点击保存按钮时尝试调用jQuery函数。但是我点击按钮时没有得到任何响应。
<button type="button" id="save" class="btn btn-primary pull-right">Save Expense</button>
$('#save').on('click', function() {
alert("test");
var data = $('form').serialize();
console.log("data" + data);
$.ajax({
type: "POST",
url: "saveExpense",
data: data,
cache: false,
success: function(data) {
alert("Success");
}
});
});
答案 0 :(得分:0)
像这样创建一个点击事件,这将解决您的问题。
$(document).on('click','#save', function() {
alert("test");
var data = $('form').serialize();
console.log("data" + data);
$.ajax({
type: "POST",
url: "saveExpense",
data: data,
cache: false,
success: function(data) {
alert("Success");
}
})
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" id="save" class="btn btn-primary pull-right">Save Expense</button>
&#13;