I have this code to show an alert when the text in the input is changed. the script works well. but anyone can explain to me why I don't see the success alert. but when I click on submit the text on video and on my database is changed only i don't see the success alert. And if I would like to insert instead of alert-success,
for example, sweet alert, just replace alert-success with Swal.fire(....)
or not?
$(document).ready(function() {
$('#updForm').submit(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: 'config/locale.php',
data: $(this).serialize(),
success: function(response)
{
var jsonData = JSON.parse(response);
// user is logged in successfully in the back-end
// let's redirect
if (jsonData.success == "1")
{
alert('perfect!!');
}
else
{
alert('Invalid Credentials!');
}
}
});
});
});
<form id="updForm" method="post" >
<div class="form-group">
<label>Descrizione locale</label>
<textarea rows="10" class="form-control" id="description" name="description" spellcheck="true"><?php echo htmlspecialchars($user['description']); ?></textarea>
</div>
<button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Salva dati</button>
</form>
<p>
<a href="reset-password.php" class="btn btn-warning">Reset Your Password</a>
<a href="logout.php" class="btn btn-danger">Sign Out of Your Account</a>
</p>
</body>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
this is php file
require_once "config.php";
// Initialize the session
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
$id = $_SESSION["username"];
$sql = "SELECT id_user, username, restaurant_name, description , logo , id_user_type FROM vm_users WHERE username = ?";
$statement = $link->prepare($sql);
$statement->bind_param('s', $id);
$statement->execute();
$result = $statement->get_result();
$user = $result->fetch_array(MYSQLI_ASSOC);
$description = $_POST['description'];
if(isset($description)){
$id = $_SESSION["username"];
$query = $link->prepare("UPDATE vm_users SET description= ? WHERE username = ? ");
$query->bind_param('ss', $description, $id);
echo json_encode(array('success' => 1));
$result = $query->execute();
}
else {
echo json_encode(array('success' => 0));
}
$result->close();
$statement->close();
$link->close();