2012-04-04 5 views
2

Ich bin neu in Grails, also könnte dies ein dummer sein .... aber ich versuche, das Json-Objekt aus dem jquery-Client in Grails mit Grails REST zu bekommen, aber ich bekomme null . Könnte eine kleine gitch sein, aber seine für meine ersten paar Datenflüsse in Hindernisse habe ichErhalten von JSON-Objekt mit Params in Grails REST

meine Jquery Aufruf testen wollen:

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'); 
    } 
}); 

Mein 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"] 
     } 
    } 
+0

Sind Sie sicher, dass Ihre Daten korrekt vom Client gesendet wurden? Haben Sie Ihren AJAX-Anruf mit Firebug oder einem anderen Tool überprüft? – aiolos

+0

Hi Aiolos - Sie haben Recht, ich habe versucht, mit Chrom-Browser zu tun und es funktioniert, aber das gleiche Stück Code funktioniert nicht mit Internet Explorer 8. Warum? Ich habe es noch nicht herausgefunden, aber IE hat mir ein Problem gegeben. Vielen Dank für Ihre Zeit !! – user1313900

Antwort

0

verwenden:

def jsonObject=request.JSON 
Verwandte Themen