I am currently in the process of developing a RESTful Web Service using MySQL Community Server alongside jQuery AJAX
Unfortunately, my usage of jQuery AJAX is not functioning as expected. When attempting to add, delete, update a product, or retrieve all products, my webpage does not respond to any clicks.
I am unsure of what I may have overlooked on my webpage. Would you be able to assist me in resolving this issue?
Here is a snippet from my webpage:
<button onclick="addProduct()"> Save </button>
<script>
function addProduct() {
var productData = {
id: document.getElementById("id").value,
name: document.getElementById("name").value,
}
$.ajax({
url: "http://127.0.0.1:3306/app/products",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
type: "POST",
dataType: "json",
data: JSON.stringify(productData)
});
}
</script>
Here is a segment from my java class:
@RequestMapping(method = RequestMethod.GET, value = "/app/products")
public List<Product> getAllProducts(){
return productService.getAllProducts();}
@RequestMapping(method = RequestMethod.POST, value = "/app/products")
public void addProduct(@RequestBody Product product){
productService.addProduct(product); }