javascript - html uses js validation causing ajax submission to fail

WBOY
Release: 2016-08-04 09:22:13
Original
1167 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!