提交表单数据而无需重新加载页面

我试图提交表单而不使用jQuery重新加载页面本身,但数据没有显示,表单正在重新加载,这是不需要的。

jQuery代码:

function submitFormData() { var firstval = $("#first").val(); var second = $("#second").val(); //var operator = $("#myselect option:selected" ).text(); $.post("index.php",{first:first,second:second}, function(data){ $('#results').html(data); $('#formcal')[0].reset(); }); } 

这是同一页面上的HTML代码(INDEX.PHP):

 
+ - * /

防止表单提交的默认操作。

 function submitFormData(event) { // prevent the default action event.preventDefault(); // Other pieces of code 

您可以在表单上使用onsubmit事件。