Home >Backend Development >PHP Tutorial >javascript - html uses js validation causing ajax submission to fail
I used js to do form verification, but the subsequent ajax submission did not respond.
<code><script type="text/javascript"> $('#formmain').submit(function() { if($("input[name='age']").val()==19&&$("input[name='sex']:checked").val()=="both"&&$("#address").find("option:selected").text()=="和盛堂"&&$("input[id='date']").val()=="2016-04-26") { alert('回答正确!'); $(function(){ var my_data=new Array(); $.ajax({ url: "sql.php", type: "POST", data:{trans_data:right}, //dataType: "json", error: function(){ alert('Error loading XML document'); }, success: function(data,status){//如果调用php成功 alert('data'); } }); }); } else{ alert('回答错误!请重新回答~'); return false;} }); </script></code>
Excuse me, what is the problem? Thank you
I used js to do form verification, but the subsequent ajax submission did not respond.
<code><script type="text/javascript"> $('#formmain').submit(function() { if($("input[name='age']").val()==19&&$("input[name='sex']:checked").val()=="both"&&$("#address").find("option:selected").text()=="和盛堂"&&$("input[id='date']").val()=="2016-04-26") { alert('回答正确!'); $(function(){ var my_data=new Array(); $.ajax({ url: "sql.php", type: "POST", data:{trans_data:right}, //dataType: "json", error: function(){ alert('Error loading XML document'); }, success: function(data,status){//如果调用php成功 alert('data'); } }); }); } else{ alert('回答错误!请重新回答~'); return false;} }); </script></code>
Excuse me, what is the problem? Thank you
This part of you
<code class="js">$(function(){ var my_data=new Array(); $.ajax({ url: "sql.php", type: "POST", data:{trans_data:right}, //dataType: "json", error: function(){ alert('Error loading XML document'); }, success: function(data,status){//如果调用php成功 alert('data'); } }); });</code>
changed to
<code> var my_data=new Array(); $.ajax({ url: "sql.php", type: "POST", data:{trans_data:right}, //dataType: "json", error: function(){ alert('Error loading XML document'); }, success: function(data,status){//如果调用php成功 alert('data'); } });</code>