Obtaining JSON object using params in Grails REST

Go To StackoverFlow.com

2

I am new to Grails so this might be a silly one....however I am trying to get the json object from the jquery client in Grails using Grails REST but i am getting null. Might be a small gitch but its created in impediments for my first few dataflows I want to test

my jquery call:

var jsonObjects = [{name: "IPAD", input: "IPAD", program: "IPAD", destination: "IPAD",    
priority: "IPAD", userData: "IPAD", email: "IPAD", webCallBackURL: "IPAD", copyToLocal:    
"IPAD", scriptPreProcess: "IPAD", deleteSource: "IPAD", moveToSource: "IPAD",    
scriptPostProcess: "IPAD", inputImage: "IPAD", leftImage: "IPAD", topImage: "IPAD", 
opacityImage: "IPAD", bImageAdAvBlanking: "IPAD"}] 

$.ajax({ 
    type: "POST", 
    url: 'http://localhost:8080/Medusa/jobControlREST/save', 
    data: {ipad: JSON.stringify(jsonObjects)}, 
    contentType: "application/json; charset=utf-8", 
    dataType: "json", 
    beforeSend: function(x) { 
        if (x && x.overrideMimeType) { 
            x.overrideMimeType("application/json;charset=UTF-8?"); 
        } 
    },
    success: function() { 
        alert('hi'); 
    } 
}); 

My Grails:

def save = { 
    def jsonString = params['ipad'] //returns null 
    def json = JSON.parse(jsonString) // returns null obviously 
    println "this is POST call" +json // gets printed but json is null...sign ( 
} 

urlmapping: 
    "/$controller/$action?/$id?"(parseRequest:true) {
        constraints { 
            action = [GET:"index", POST:"save", PUT:"update", DELETE:"remove"] 
        }
    }
2012-04-04 22:16
by user1313900
Are you sure that your data is sent correctly from client? Have you checked your AJAX call using Firebug or some other tool - aiolos 2012-04-05 05:29
Hi Aiolos - you are right, I tried to do with using chrome browser and it worked however the same piece of code does not work with internet explorer 8. Why? I did not figure it out yet but IE gave me a problem for sure. thanks a lot for your time! - user1313900 2012-04-05 05:50


0

Use this:

def jsonObject=request.JSON
2016-04-01 23:43
by André Peregrina
Ads