The script I have in my HTML file is printing the ajax script instead of an actual message. HTML script:
<script src="{{url_for('static', filename='jquery-3.6.0.min.js')}}"></script>
<script src="{{ url_for('static', filename='sign_up.js')}}"></script>
<script>
$(document).ready(function(){
$("#p3").keyup(function(){
var username = $(this).val().trim();
if(username != ''){
$.ajax({
url: '../static/ajaxfile.php',
type: 'GET',
data: {username: username},
success: function(response){
$('#uname_response').html(response);
}
});
}else{
$("#uname_response").html("");
}
});
});
</script>
ajaxfile.php
<?php
include "config.php";
if(isset($_POST['username'])){
$username = mysqli_real_escape_string($con,$_POST['username']);
$query = "select count(*) as cntUser from users where username='".$username."'";
$result = mysqli_query($con,$query);
if(mysqli_num_rows($result)){
$row = mysqli_fetch_array($result);
$count = $row['cntUser'];
if($count > 0){
$response = "<span style='color: red;'>Not Available.</span>";
}else{
$response = "<span style='color: green'>Available.</span>";
}
}
echo $response;
die;
}
?>
The output on the webpage is "0){ $response = "Not Available."; }else{ $response = "Available."; } } }"
Under the username text box. The username textbox has an id of "username", and I checked my terminal, its querying the ajaxscript.php file with the username data, but just getting an incorrect repsonse.