JQuery Developer Question:

Download Job Interview Questions and Answers PDF

How to get server response from an AJAX request using Jquery?

JQuery Developer Interview Question
JQuery Developer Interview Question

Answer:

When invoking functions that have asynchronous behavior We must provide a callback function to capture the desired result. This is especially important with AJAX in the browser because when a remote request is made, it is indeterminate when the response will be received.
Below an example of making an AJAX call and alerting the response (or error):

Code:
$.ajax({
url: 'pcdsEmpRecords.php',
success: function(response) {
alert(response);
},
error: function(xhr) {
alert('Error! Status = ' + xhr.status);
}
});

Download JQuery Developer Interview Questions And Answers PDF

Previous QuestionNext Question
How you debug Jquery code/ debug jquery?Can you please explain the difference between onload() and document.ready() function used in jQuery?