Prasanth Klr Prasanth Klr - 4 months ago 5
Ajax Question

json not working in code

I have some code how to link php using json.



<?php

$con = mysqli_connect('localhost', 'ganesh', '5565','ganesh');
$sql = "INSERT INTO `equation`VALUES('','123','123')";
$result = mysqli_query($con, $sql);

echo ' Updated successfully';

?>

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>

</head>
<body>
<script>

$(document).ready(function(){
$("button").click(function(){
$.getJSON("insert12.php", function(result){
$.each(result, function(result){
$("#file").html(result);
});
});
});
});

</script>

<input type="text" id="input"placeholder="Search..." >
<button>solve</button>

<div id="result">
<ul></ul>
</div>
<ul id="file">


</ul>


</body>
</html>





json are not working how to get the input data please help me. for example input(some text) output(some text) are print using json

Answer

In your PHP code you have to give response in JSON format

<?php

$con = mysqli_connect('localhost', 'ganesh', '5565','ganesh');
$sql = "INSERT INTO `equation`VALUES('','123','123')";
$result = mysqli_query($con, $sql);

$response=array("type"=>"success","message"=>"Updated successfully");
ob_clean();
echo json_encode($response);
Comments