AJAX Interview Questions Answers

By Dhananjay yadav June 29, 2018
AJAX Interview Questions Answers

What is AJAX?
Full form of AJAX is : Asynchronous JavaScript And XML.
AJAX facilitate a web pages to be updated asynchronously by exchanging data with a web server in background. It can update the webpage without reloading the whole page.

What are the main components that are used by AJAX?
AJAX components are :
1-A browser built-in XMLHttpRequest object
2-JavaScript and HTML DOM


What is XMLHttpRequest Object?
The XMLHttpRequest object can be used to request data from a web server without refreshing the whole page.It can send data to server in background and can request and receive data in background.


What are the request type used by XMLHttpRequest Object?
open() : It specify the type of request GET or POST
send() : Sends the GET request to the server
send(string) : Sends the POST request to the server

Give an Example of jQuery AJAX call.
A POST method AJAX example in jQuery:

  var empId = $("ul .emp").first().attr("id");
  var request = $.ajax({
    url: "myajaxcall.php",
    type: "POST",
    data: {id : empId},
    dataType: "json"
  });

  request.done(function(response) {
    console.log(response);
  });

  request.fail(function(jqXHR, ajax_status) {
    alert( "Request failed: " + ajax_status );
  });
 

What is difference between xhr.status and xhr.readyState.
xhr.status : used to determine whether the request was successful or not.
xhr.readyState : the state of the request'
xhr.readyState zero(0) means "has not yet been sent"
xhr.readyState zero(4) means "complete and response received"
The server provides the status, while the user agent provides the readyState.











No Comment to " AJAX Interview Questions Answers "