jqlib.js是https://code.jquery.com/jquery-3.2.1.js
没有什么是在试图使用jquery 3.2.1.js使用ajax添加到数字
无法找到此代码中的错误,任何人都可以告诉我此代码中的错误在哪里
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 :(得分:3)
你有错字错误:
sucess
应为success
答案 1 :(得分: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>