Below is my code for the problem. I am trying to call php file via AJAX. I have an HTML file where after form submission, the AJAX calls the PHP file. Unfortunately, I cannot see any output.
HTML File(Body):
<form>
<label for="">Username</label>
<input type="text" name="username" value="">
<br><br>
<label for="">Password</label>
<input type="text" name="password" value="">
<br>
<button name="button" id="button" value="Submit">Submit</button>
</form>
<script type="text/javascript" src="jquery-3.2.1.min.js"></script>
<script src="login.js"></script>
My login.js file(for AJAX):
$("#button").click(function(e){
e.preventDefault();
$.ajax({
type: 'POST',
url: 'login.php'
});
});
My PHP file:
<?php
// Server credentials
$serverName = "localhost";
$username = "root";
$password = "root";
$dbName = "Blog";
//Creating connection
$db = mysqli_connect($serverName,$username,$password,$dbName);
if(!$db){
echo "error";
die($db);
}
else{
echo "er22ror";
}
mysqli_close($db);
?>