Home >Backend Development >PHP Tutorial >javascript - html uses js validation causing ajax submission to fail

javascript - html uses js validation causing ajax submission to fail

WBOY
WBOYOriginal
2016-08-04 09:22:131222browse

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

Reply content:

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>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn