jQuery interview questions and answers – Part11

101. How to get the server response from an AJAX request using Jquery?
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):

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

102. How do you update ajax response with id ” resilts”?
By using below code we can update div content where id ‘results’ with ajax response

function updateStatus() {
url: 'pcdsEmpRecords.php',
success: function(response) {
// update div id Results

103. What is the use of jQuery load method?
jQuery load method is a powerful AJAX method which is used to load the data from a server and assign the data into the element without loading the page.

104. What are the four parameters used for jQuery Ajax method?
The four parameters are
• URL – Need to specify the URL to send the request
• type – Specifies type of request(Get or Post)
• data – Specifies data to be sent to server
• Cache – Whether the browser should cache the requested page

105. What is the use of jQuery filter?
The jQuery filter is used to filter the certain values from the object list based on the criteria. Example is to filter certain products from the master list of products in a cart website.

106. What is the use of jQuery.ajax method ()?
jQuery.ajax method is used for asynchronous HTTP requests.

107. Can we use jQuery to make ajax request?
Yes. jQuery can be used for making ajax request.

108. What are various methods to make ajax request in jQuery?
Using below jQuery methods, you can make ajax calls.
• load() : Load a piece of html into a container DOM
• $.getJSON(): Load JSON with GET method.
• $.getScript(): Load a JavaScript file.
• $.get(): Use to make a GET call and play extensively with the response.
• $.post(): Use to make a POST call and don’t want to load the response to some container DOM.
• $.ajax(): Use this to do something on XHR failures, or to specify ajax options (e.g. cache: true) on the fly.

109. Is there any advantage of using $.ajax() for ajax call against $.get() or $.post()?
By using jQuery post()/ jQuery get(), you always trust the response from the server and you believe it is going to be successful all the time. Well, it is certainly not a good idea to trust the response. As there can be n number of reason which may lead to failure of response.
Where jQuery.ajax() is jQuery’s low-level AJAX implementation. $.get and $.post are higher-level abstractions that are often easier to understand and use, but don’t offer as much functionality (such as error callbacks). Find out more here.

110. What are deferred and promise object in jQuery?
Deferred and promise are part of jQuery since version 1.5 and they help in handling asynchronous functions like Ajax. Find out more here.

Sign-up for our email newsletter and get free job alerts, current affairs and GK updates regularly.
Subscribe Here (or)

Leave a Reply

Your email address will not be published. Required fields are marked *

six + = 11

Popup Dialog Box Powered By : XYZScripts.com
  • RSS
  • Facebook
  • Google+
  • Twitter