There is software that uses Ajax Get. The code below does not work. What can I do?
Javascript code:
<script>
function buy_product(cid) {
$.ajax({
url: '/buyProduct/' + cid,
type: 'get',
success: function(response) {
var result = $.parseJSON(response);
if (result["success"]) {
iziToast.success({
theme: 'dark',
message: result["message"],
timeout: 3000
}).then(function() {
window.location = "/my/products";
}, 3000);
} else {
alert("Error");
}
},
error: function(xhr, err) {
alert("Error");
}
});
}
</script>
Example response:
{"success":true,"message":"Success","status":"SUCCESS"}
Console error:
Uncaught TypeError: Cannot read properties of undefined (reading 'then')
If it output is success, "iziToast.success" is running. But window.location is not working.
2
Answers
This is how I solved the problem.
Use the
onClosed
option to specify a function that should be called when the user closes the dialog.