A RESTful Web Service using MySQL Community Server and jQuery AJAX

Viewed 80

I am trying to create a RESTful Web Service using MySQL Community Server and jQuery AJAX

My jQuery AJAX does not work properly, so if i want add, delete, update a product or retrieve all products. it simples does not react to my clicks. I do not know what I have missed on my webpage, could you help me to fix that ?

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>

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); }
1 Answers
Related