admin管理员组文章数量:1328037
I try to call server using Ajax when i click a button inside a Form. But it does not use Ajax even if i use event.PreventDefault or return false.
What could be the problem. Here is my HTML and jQuery code
<form action="/Patient/Search" id="patient-search-form" method="post">
<input type="text" id="PatientName" />
<button class="btn blue-button" id="search-patients" type="submit">
<i class="icon-save icon-white"></i><span>Search</span>
</button>
</form>
<script type="text/javascript">
$(document).ready(function () {
$('#search-patients').submit(function (event) {
event.preventDefault();
SearchPatients();
return false;
});
});
</script>
I try to call server using Ajax when i click a button inside a Form. But it does not use Ajax even if i use event.PreventDefault or return false.
What could be the problem. Here is my HTML and jQuery code
<form action="/Patient/Search" id="patient-search-form" method="post">
<input type="text" id="PatientName" />
<button class="btn blue-button" id="search-patients" type="submit">
<i class="icon-save icon-white"></i><span>Search</span>
</button>
</form>
<script type="text/javascript">
$(document).ready(function () {
$('#search-patients').submit(function (event) {
event.preventDefault();
SearchPatients();
return false;
});
});
</script>
Share
Improve this question
asked Mar 18, 2013 at 11:38
BillaBilla
5,26623 gold badges65 silver badges108 bronze badges
1
- Are you sure there is no problem in SearchPatients() function? – KA. Commented Mar 18, 2013 at 11:41
2 Answers
Reset to default 5Your submit event handler is being assigned to the button, where it should be the form:
<script type="text/javascript">
$(document).ready(function () {
$('#search-patients-form').submit(function (event) {
event.preventDefault();
SearchPatients();
return false;
});
});
</script>
Or you could bind to the button click event instead:
<script type="text/javascript">
$(document).ready(function () {
$('#search-patients').click(function (event) {
event.preventDefault();
SearchPatients();
return false;
});
});
</script>
$(document).ready(function () {
$('#search-patients').click(function (event) {
event.preventDefault();
SearchPatients();
return false;
});
});
you gave button Id there.We need to give form id.
本文标签: javascriptAjax call using Button click inside form not workingStack Overflow
版权声明:本文标题:javascript - Ajax call using Button click inside form not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742241303a2438850.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论