How to invoke a REST service

前端 未结 1 417
一生所求
一生所求 2021-01-29 08:08

I have created a REST service which retrieves data from the database as per the request made and returns it JSON format.

Now, I need to create a HTML page with a button

相关标签:
1条回答
  • 2021-01-29 08:20

    Well, all your service does is respond to HTTP requests. So, you need to send one - either

    • direct the browser to move to a corresponding URL (document.location.href = <url>), or
    • send an XMLHTTPRequest (aka AJAX) and parse the result, for which JQuery has built-in functionality.
      • then edit the currently loaded page to include the results the way you like using DOM (see e.g. Google on "jquery tutorial editing DOM" for that)
      • See e.g. AJAX Introduction - W3Schools for an AJAX overview. It describes how this happens in plain JS, jquery.ajax is a convenient wrapper over that.

    You don't need to connect you client-side stuff with the Java project in any way - REST is specifically designed to allow them to be independent.

    0 讨论(0)
提交回复
热议问题