Make a mistake $ .ajax
This is a rather strange question, but I want $ .ajax not to be able to check my crash in it, I have this jQuery code:
$(document).ready(function () {
$("#trigger").on("click", function () {
$.ajax({
url: "text.php",
success: function (data) {
$(".log").html(data.slice(0, 1000));
//alert("Load has been performed");
},
fail: function () {
$(".msg").html("Something went wrong...");
}
});
});
});
And I am calling this PHP code:
<?php
function foo()
{
return "bar";
}
print foo();
return false;
?>
and make sure it works fail: ...
. How to do it?
EDIT
I changed text.php as follows:
<?php
throw new LogicException("Failed");
also:
<?php
header("HTTP://this.does.not.exist");
But this is still displayed in the area $(".log")
even if it is not done.
Noticed that I was using the crash function incorrectly, now changed my jQuery to:
$(document).ready(function () {
$("#trigger").on("click", function () {
$.ajax({
url: "text.php"
}).done(function (data) {
$(".log").html(data.slice(0, 1000));
}).fail(function () {
$(".msg").html("Something went wrong...");
}).always(function () {
alert("One way or another, we did it!");
});
});
});
Also, if it helps, I use these scripts for the jQuery libraries:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
+3
source to share
2 answers