0 votes
1 view
in DevOps and Agile by (19.8k 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 (63.4k 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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...