jqlib.js is https://code.jquery.com/jquery-3.2.1.js
nothing is happing i m trying to add to number using ajax using jquery 3.2.1.js
cant find the error in this code can anyone tell me where is the error in this code
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";
}
?>
-
blank nothing is showingShashi Kumar– Shashi Kumar2017年07月01日 12:42:18 +00:00Commented Jul 1, 2017 at 12:42
-
check @SepehrRaftari 's answerJigar Shah– Jigar Shah2017年07月01日 12:43:20 +00:00Commented Jul 1, 2017 at 12:43
-
@AyushmanKasyap check SepehrRaftari's answer, and if it helps, upvote and accept it.YvesLeBorg– YvesLeBorg2017年07月01日 12:43:50 +00:00Commented Jul 1, 2017 at 12:43
2 Answers 2
you have a typo error:
sucess should be success
answered Jul 1, 2017 at 12:40
Sepehr Raftari
311 silver badge3 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Change your script as follow and check whether any alert is showing or not
<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>
answered Jul 1, 2017 at 12:39
user5139148
2 Comments
YvesLeBorg
@Fairy requesting a clarification from OP would be a fine comment methinks, but not answer material. Anyways, you also duplicated OP's typo.
default