在我们点击保存的下面的表格中,我们只向服务器提交表单提交请求。
<form id="form1" action="service1" method="POST">
<button id="id1" onclick="getcount('emp')" >clickhere</button>
<input id="save" type="submit" class="btn-small btn-primary" value="Save" name="Save"/>
</form>
但是当我们点击clickhere按钮时,我们会收到两个服务器请求。 即1.通话后服务1 2.在getCount()函数中进行服务调用。
但我只需要getCount()函数服务调用。
我们如何处理上述情况?
答案 0 :(得分:2)
将add =“button”添加到进行getcount()调用的按钮,以便它覆盖默认的“提交”行为。
<button id="id1" type="button" onclick="getcount('emp')" >clickhere</button>