I am trying to submit a form and get a result from an AJAX call. However, the error block is triggered when submitting the form.
If I change the <form> to a <div> and change the $("form#main_frm").submit(...) to $("#main_frm").click(...), it works. What am I doing wrong with form? Thanks in advance.
<!DOCTYPE html>
<HTML>
<HEAD>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<TITLE>main</TITLE>
<SCRIPT>
$(document).ready(function(){
$("form#main_frm").submit(function(){
process();
});
});
function process()
{
$.ajax({
type: "POST",
dataType: "json",
url: "process.php",
data: "",
success: function(data, textStatus, jqXHR)
{ $("#result").text(JSON.stringify(data)); },
error: function(jqXHR, textStatus, errorThrown)
{ $("#result").append(errorThrown + ": " + textStatus); }
});
}
</SCRIPT>
</HEAD>
<BODY>
<FORM METHOD=POST ID='main_frm'>
<BUTTON TYPE=SUBMIT>SUBMIT</BUTTON>
</FORM>
<DIV ID='result'></DIV>
</BODY>
</HTML>