0

I am trying to test the error callback using the below scenarios :

  1. Change my url : "telemetry.php" to url : "asdasfjgafas.php"
  2. Have <?php header("HTTP/1.1 404 Not Found"); exit() > inside telemetry.php

But, I don't get alert() of the error callback even after trying 1. and 2. separately!

My .js content making AJAX request using jQuery :

$.ajax({

    url     :   "telemetry.php",
    data    :   ({
                    DshBrdName  : strFullDashBoardName,
                    DshBrdID    : currentDashboard, 
                    r           : Math.random()
                }),
    success :   function(data, textStatus, jQxhr){
                    alert(textStatus); 
                },
    error   :   function(jqXHR, textStatus, errorThrown){
                    alert(textStatus);
                    alert(errorThrown);
                },
    type    :   "POST"
});

P.S : I am able to get success alert when I have valid url and valid php code!

1 Answer 1

1

I can see a typo in your error block:

function(jqXHR, textStatus, errorThrown){
                alert(testStatus); // should be textStatus?
                alert(errorThrown);
            },

EDIT

From the js, point of view, everything seems ok, as your snippet below (I replaced the undefined variables with string) alerts the error (since this php script obviously isn't found). You may want to give more detail about what goes on at the server side...

$.ajax({

    url     :   "telemetry.php",
    data    :   ({
                    DshBrdName  : 'strFullDashBoardName',
                    DshBrdID    : 'currentDashboard', 
                    r           : Math.random()
                }),
    success :   function(data, textStatus, jQxhr){
                    alert(textStatus); 
                },
    error   :   function(jqXHR, textStatus, errorThrown){
                    alert(textStatus);
                    alert(errorThrown);
                },
    type    :   "POST"
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Sign up to request clarification or add additional context in comments.

3 Comments

Yes you probably have error in console that says that testStatus is undefined.
Sorry guys.. I was manually typing those alerts in the stackoverflow page instead of copying from my php file... This is not a typo issue! In the real code, it is indeed alert(textStatus)
Running your script here gets the alert, so the problem may not be with javascript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.