Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.7k points)

Within an ajax request how can the error callback be tested? Is it possible to simulate a network connection error?

$.ajax({

        url: "myUrl",       

        type: 'post',

        dataType : "json",

        data : ({

            myJson

        }),

        success : function(jsonSaveResponse) {  

        },

        error: function (xhr) {

    } 

    }); 

1 Answer

0 votes
by (62.9k points)

You could simply put an incorrect URL into the URL attribute of the AJAX call., something like this:

 <?php

    header("HTTP/1.0 404 Not Found");

    exit();

    //the rest of your code

You can simply comment it out later when you're done testing your error function.

Browse Categories

...