<?php
session_start();
?>
<?php
$con=mysqli_connect("localhost","root","") or die(mysqli_error());
mysqli_select_db($con, "sada_r_t_m");
$result=mysqli_query($con, "SELECT * FROM products ");
echo "<h2 fontsize = '26' color = 'yellow' align = 'center'>Flipkart</h2>";
echo "<table border = '5' cellpadding = '12' align = 'center' background-color = '#84ed86' color = '#761a9b' >";
echo "<tr>";
echo "<th>SNO</th>";
echo "<th>Product Name</th>";
echo "<th>Price</th>";
echo "<th>Cart</th>";
echo "</tr>";
while($data = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<th>".$data['id']."</th>";
echo "<th>".$data['name']."</th>";
echo "<th>".$data['price']."</th>";
echo "<th><a href='#' Onclick='add(".$data['id'].")'>Add to Cart</a></th>";
echo "</tr>";
}
echo "</table>";
?>
<script type="text/javascript">
function add(id){
alert(id);
$.ajax({
url: '../ajax.php',
type: 'POST',
data: { action: "add",id: id, val:1} ,
//contentType: 'application/json; charset=utf-8',
success: function (response) {
alert(response.status);
},
error: function () {
alert("error");
}
});
}
</script>
I passed the values through ajax in php. I wrote only in single php page.
How to pass values through ajax in php. While passing values,i am getting below error
Uncaught ReferenceError: $ is not defined
How to achieved this error i am new to php.