2017-07-01 85 views
0

jqlib.js是https://code.jquery.com/jquery-3.2.1.js什麼是AJAX代碼中的錯誤

nothing is happing i m trying to add to number using ajax using jquery 3.2.1.js

無法找到在此代碼中的錯誤誰能告訴我哪裏是在此代碼

add.php

錯誤
<html> 
<body> 
<script type="text/javascript" src="jqlib.js"></script> 
    <form id="tt"> 
     <table> 
      <tr> 
       <td>Enter first Number</td> 
       <td><input type=text name=t1 ></td> 
      </tr> 
      <tr> 
       <td>Enter 2nd Number</td> 
       <td><input type=text name=t2></td> 
      </tr> 
      <tr> 
       <td><input type=button value="OK" onClick="cal()"></td> 
      </tr> 
      <tr> 
      <td>Addition</td> 
      <td><input type=text name=t3 id="tt1"></td> 
      </tr> 
     </table> 
    </form> 
</body> 
</html> 
<script type="text/javascript"> 
    function cal() 
    { 
     var frm = $("#tt"); 

     $.ajax(
     { 
      type:"POST", 
      url:"ajax.php", 
      data:frm.serialize(), 
      sucess:function (data) 
      { 
       $("#tt1").val(data); 
      } 
     }); 

    } 
</script> 

ajax.php

<?php 
if(!empty($_POST)) 
{ 
if(($_POST['t1']!="")|| ($_POST['t2']!="")) 
{ 
    $z = $_POST['t1'] + $_POST['t2']; 

} 
else 
{ 
    $z ="please enter data"; 
} 
echo $z; 
} 
else 
{ 
echo "please enter data"; 
} 
?> 
+0

空白什麼都不顯示 –

+0

檢查@SepehrRaftari的回答 –

+0

@AyushmanKasyap檢查SepehrRaftari的答案,如果有幫助,upvote並接受它。 – YvesLeBorg

回答

0

更改腳本遵循和檢查任何警報是否顯示或不

<script type="text/javascript"> 
function cal() 
{ 
    var frm = $("#tt"); 

    $.ajax(
    { 
     type:"POST", 
     url:"ajax.php", 
     data:frm.serialize(), 
     sucess:function (data) 
     { 
      $("#tt1").val(data); 
      alert('Success: '+data); ///---> this show alert with success and content 
     }, 
     error:function(a,b,c) 
     { 
      alert(c); //---> If error happen it will show alert(); 
     } 
    }); 

} 
</script> 
+0

什麼都沒發生沒有提示 –

+0

檢查您的瀏覽器控制檯。它會顯示任何jQuery的錯誤 –

+1

@Firyay要求來自OP的澄清將是一個美好的評論methinks,但不回答材料。無論如何,你也重複OP的錯字。 – YvesLeBorg

3

你有一個錯字錯誤: sucess應該success

+0

找到了thanku錯誤 –