Reputation: 1523
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
Upvotes: 2
Views: 3620
Reputation: 1234
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 return
ing it; like :
def addPurchase = {
def result = cartService.addPurchase(session,params)
log.debug"Results from addPurchase" + result
response.status = 200
render result as JSON
}
Upvotes: 12