Home >Backend Development >PHP Tutorial >How Can I Retrieve the Exact Error Response Text from a jQuery $.ajax Error?
Retrieving jQuery $.ajax Error Response Text
In jQuery, it can be challenging to retrieve the exact error response text when an AJAX request fails. The default behavior only returns a general "error" message. However, we can access the response text by modifying our error handling function.
In the example provided, the PHP code sends a 500 Internal Server Error with the text "Gone to the beach". By default, jQuery's error function only displays "error" without any detailed information.
To obtain the response text, modify the error function as follows:
error: function(xhr, status, error) { var err = eval("(" + xhr.responseText + ")"); alert(err.Message); }
In this updated code:
By implementing this adjustment, jQuery can now effectively display the error response text, providing more informative feedback during error handling.
The above is the detailed content of How Can I Retrieve the Exact Error Response Text from a jQuery $.ajax Error?. For more information, please follow other related articles on the PHP Chinese website!