How to use ajaxError() Method in JQuery AJAX

In this article, I will explain use of ajaxError() Method in JQuery AJAX.
  • 2949

JQuery AJAX ajaxError() Method

  • ajaxError() method add a function to be execute when an AJAX request completes with an error.

  • ajaxError() method is a AJAX Event.

Syntax

$(selector).ajaxError(function(event,xhr,options,exc))

function(event,xhr,options)  The function is run when the request is fail.
 parameters:

  • event - Event parameter contains the event object.

  • xhr - xhr parameter contains the XMLHttpRequest object.

  • options - option parameter contains the options used in the AJAX request.

  • exc - exc parameter contains the JavaScript exception.

 

Example

The following example show the use of ajaxError() method.

 

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("div").ajaxError(function () {

            alert("Error occured in select file...!");

        });

        $("button").click(function () {

            $("div").load("wrongfile.txt");

        });

    });

</script>

</head>

<body>

<div><h2>error() method example</h2></div>

<button>click for change article text</button>

</body>

</html>

Output

error.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.