Save data [POST] using Java Web Services and jQuery Ajax

Hi guys, Bushan here, welcome back to B2 Tech! Today in this article I will teach you how to make POST request using jQuery Ajax, so let’s get started! To make POST request, I have already created a Java web service, I will use the same web service in this article.

I have created this web service using Spring REST. To make a POST request on this web service, we need to POST a JSON data to this web service. I have already created a table in the database. We have 3 columns, Id, Title and Author, where Id is the Primary key. We will send the book title and author name in JSON format, and it will submit the data to the database.

NOTE: I have created this web service using Spring REST but you can create using any server-side technology.

Now let’s design a web page where the user will enter the book title and author name and when they click the submit the button we will make POST request on the web service using jQuery Ajax.


At this point test your work by running the file in a web browser, POST the below JSON data to the web service. if you see the alert message saying saved successfully then the application is working fine.

Next step is to display all the records in HTML table just below the form as soon as the user submits the form. This will help the user to view all the books in the HTML page itself.

We will use the same approach as we discussed in our previous article, we will make GET request using jQuery Ajax.

Here is the complete source code of it,

So now let’s open the file in a browser and you will see the following page. If you see the following page then congratulations you made it.

That’s it for this article, I hope this article is helped you in one or the other way if you have questions leave your questions in the comment section, I will try to answer it. In the next article we will discuss DELETE request/deleting a record. If you like this article, do share this with your friends and colleagues, i will see in the next article.


About the author

Bushan Sirgur

Well, I am Bushan Sirgur from Banglore, India. Currently, I am working as a Software Developer in a Service Base Company. I am interested in JAVA/J2EE, Angular 2, JavaScript, jQuery, MongoDB.

View all posts


Leave a Reply

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