AJAX requests (ok)
Previoussweetalert bản chuẩn (ok)Nextsweetalert2 bản chuẩn (ok) cái này dùng hay hơn sweetalert (ok)
Last updated
Last updated
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="http://localhost/library/jquery/jquery.min.js"></script>
<script type="text/javascript" src="http://localhost/library/sweetalert/sweetalert.min.js"></script>
</head>
<body>
<button type="button" id="button">Nhấn vào đây!</button>
<script>
jQuery(document).ready(function($) {
$('#button').click(function(event) {
swal({
text: 'Search for a movie. e.g. "La La Land".',
content: "input",
button: {
text: "Search!",
closeModal: false,
},
})
.then(name => {
if (!name) throw null;
return fetch(`https://itunes.apple.com/search?term=${name}&entity=movie`);
})
.then(results => {
return results.json();
})
.then(json => {
const movie = json.results[0];
if (!movie) {
return swal("No movie was found!");
}
const name = movie.trackName;
const imageURL = movie.artworkUrl100;
swal({
title: "Top result:",
text: name,
icon: imageURL,
});
})
.catch(err => {
if (err) {
swal("Oh noes!", "The AJAX request failed!", "error");
} else {
swal.stopLoading();
swal.close();
}
});
});
});
</script>
</body>
</html>