Federico
Federico

Reputation: 58

Grails Ajax callback not rendering/responding properly

I'm doing an ajax request to an own rest api and trying to print in an alert the message I get.
The point is I'm getting the following error: SyntaxError: Unexpected token :

The code that makes the call is:

$.ajax({
        url:"${g.createLink(controller:'report',action:'show')}",
        dataType: 'json',
        data: {
            data: jSon,
        },
        success: function(data) {
            alert(data)
        },
        error: function(request, status, error) {
            alert(error)
        },
        complete: function() {
        }
    });

The return value i'm printing in the controller is:

JSON: {"results":"SELECT cliente.edad FROM Cliente cliente,Local local WHERE Local.numero==3 GROUP BY Cliente.edad ORDER BY Cliente.edad undefined""}

And what I'm doing in the controller is:

println "JSON: " + java.net.URLDecoder.decode((String)apiResponse.json)
    render java.net.URLDecoder.decode((String)apiResponse.json)

I have also tried with respond instead of render but same error

Upvotes: 1

Views: 1603

Answers (1)

Neoryder
Neoryder

Reputation: 897

Try using render as JSON

def results = ['a':'AA','b':'BB']

render results as JSON

Upvotes: 1

Related Questions