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
renderthe result instead ofreturning it; like :