I have the following mapping in my URLMappings
addPurchase:"/addPurchase" {
controller = "cart"
action = "addPurchase"
}
I make an AJAX call from my GSP
function addPurchase(purchaseJSON, amount) {
$.ajax({
url: 'addPurchase',
data: {
purchase: purchaseJSON
// quantity: amount
},
type : "POST",
complete:function(data) {
updateCart();
updateOrderSummary(data);
}
});
}
My controller code is
def addPurchase = {
def result = cartService.addPurchase(session,params)
log.debug"Results from addPurchase" + result
response.status = 200
return result as JSON
}
Eventhough I see the output in my console, I get an error 404 in my browser. Why is it happening ? My version of grails is @ 1.3.7
You're actually returning a result whereas the required response is a 'text/html' or 'text/json'
So in your controller you should render the result instead of returning it; like :
def addPurchase = {
def result = cartService.addPurchase(session,params)
log.debug"Results from addPurchase" + result
response.status = 200
render result as JSON
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With