What are the various states in XMLHttpRequest and how do we check the same? OR How can we get response text? OR How can we send request to the server using the XMLHttpRequest component?

 Posted by ArticlesMaint on 10/1/2009 | Category: ASP.NET AJAX Interview questions | Views: 8235

Note :- All the above answers are discussed in detail in the below section.

  • Abort ():- This method cancels a user request.

  • getAllResponseHeaders ():- Returns a collection of HTTP headers as string. If you want a specific header value, you can use getResponseHeader (“header name”)

  • Open (“method”, “URL”, “async”, “uname”, “pswd”):- This method takes a URL and other values needed for a request. You can also specify how the request is sent by GET, POST, or PUT. One of the important values is how this request will be sent asynchronously or synchronously. True means that processing is carried after the send () method, without waiting for a response. False means that processing is waits for a response before continuing.

  • Send (content):- Sends a request to the server resource.

  • SetRequestHeader (“label”,” value”):- Sets label value pair for a HTTP header.

  • Onreadystatechange: - This is a event handler, which fires at every state change.

  • Ready State: - Returns the current state of the object.

    • 0 = uninitialized

    • 1 = loading

    • 2 = loaded

    • 3 = interactive

    • 4 = complete

If you want to check the state use if (xmlHttpObj.readyState ==4).

  • Response Text: - Returns the response in plain string.

  • Response: - Returns the response as XML. Therefore, this gives us DOM object model, which can then be traversed.

  • Status: - Returns the status as a numeric For instance 404 for "Not Found" or 200 for "OK", 500 for "Server Error" etc.

  • Status Text: - Returns the status as a string. For instance, "not found" or "OK".

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response