RESTful web service using MySQL Community Server and jQuery AJAX
I am trying to create a RESTful web service using MySQL Community Server and jQuery AJAX
My jQuery AJAX is not working correctly, so if I want to add, remove, update a product or get all products. it just doesn't respond to my clicks. I don't know what I missed on my webpage, can you help me fix this?
On my web page:
<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>
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); }
+3
user8349224
source
to share