Web Development with jQuery®

(Elliott) #1

(^486) ❘ APPENDIX A EXERCISE ANSWERS
bapp01.indd 02/18/2015 Page 486
CHAPTER 7



  1. In the context of an AJAX request, the only difference between GET and POST requests is
    that a GET request has a concrete limitation on the amount of data you can pass; the actual
    limit varies from browser to browser. A GET request can also be slightly more effi cient.

  2. A REST service implements more meaning in HTTP requests by providing additional meth-
    ods that describe data manipulation, such as ADD or DELETE. In addition, a REST service
    may also be implemented to standardize server responses so that they utilize the proper
    HTTP error codes.

  3. An optional second argument to the $.get() method allows you to pass data along with the
    request, either as a query string or as a JavaScript object literal.

  4. You access the JSON object in the variable that you assign to the fi rst argument of the call-
    back function that you specify for the $.getJSON() method. This variable can have any name
    you like.

  5. Accessing the contents of the element looks something like this:


$.get(
'/url/to/request.xml',
function(xml)
{
alert($(xml).text());
}
);


  1. The load() method.

  2. In the JavaScript, jQuery sets AJAX events globally via a call to the $.ajaxSetup() method,
    which takes a list of options that are formatted as a JavaScript object literal. The before-
    Send property specifi es a callback function that is executed before every AJAX request. The
    success property specifi es a callback function that is executed upon every successful AJAX
    request. The error property specifi es a callback function that is invoked upon encounter-
    ing an HTTP error. Finally, the complete callback function is executed when the request has
    completed, after the success or error callbacks have been executed, depending on whether
    the request was successful.

  3. One method is by using jQuery’s AJAX event methods like ajaxStart() and ajaxSuccess();
    another is via jQuery’s $.ajax() method.

  4. Select the form elements you want to get the values of; then call the serialize() method.

  5. You use the type property to set the request method to DELETE. You use the contentType
    property to set the MIME type of the request to signal to the server that the body of the
    request is a JSON object. Then you pass the JSON data to send in the body of the request
    within the data property. An example of creating this call using the $.ajax() method follows:
    $.ajax({
    url : '/Server/Example',
    contentType : "application/json; charset=utf-8",
    type : 'DELETE',


http://www.it-ebooks.info

Free download pdf