This guide walks you through writing a simple jQuery client that consumes a Spring MVC-based RESTful web service.

What you will build

You will build a jQuery client that consumes a Spring-based RESTful web service. Specifically, the client will consume the service created in Building a RESTful Web Service with CORS.
The jQuery client will be accessed by opening the index.html file in your browser, and will consume the service accepting requests at:
The service will respond with a JSON representation of a greeting:
{"id":1,"content":"Hello, World!"}
The jQuery client will render the ID and content into the DOM.

What you will need

  • About 15 minutes
  • A favorite text editor
  • A modern web browser
  • An internet connection

Create a jQuery Controller

First, you will create the jQuery controller module that will consume the REST service:
$(document).ready(function() {
        url: ""
    }).then(function(data) {
This controller module is represented as a simple JavaScript function. It uses jQuery’s$.ajax() method to consume the REST service at If successful, it will assign the JSON received to data, effectively making it a Greeting model object. The id and content are then appended to the greeting-id and greeting-content DOM elements respectively.
Note the use of the jQuery promise .then(). This directs jQuery to execute the anonymous function when the $.ajax() method completes, passing the data result from the completed AJAX request.

Create the Application Page

Now that you have a jQuery controller, you will create the HTML page that will load the client into the user’s web browser:

        </span><span class="pln" style="color: rgb(0, 0, 0);">Hello jQuery</span><span class="tag" style="color: rgb(0, 0, 136);">