Skip to Content
0
Jun 08, 2016 at 01:38 PM

how to send json model via ajax?

876 Views

Hi all,

I am currently implementing a web app which store the user selected data in a JSON model and send it back to the server side, since the server side java program only acceptsJOSN encoded data. Therefore, I have to send the JSON model via ajax to java servlet and let java code further work with it. However, when doing so, I wonder how can I send JSON model in sapui5 via ajax?

should I directly assign model to the data configuration of ajax as follows

$.ajax({

url: // url of servlet

type: "POST",

contentType: "application/json",

dataType: "json",

data:{

jsonData: this.getView().getModel("model name")

}

})

or should I first convert the json model into corresponding string and then assign it?

$.ajax({

url: // url of servlet

type: "POST",

contentType: "application/json",

dataType: "json",

data:{

jsonData: this.getView().getModel("model name").getJSON()

}

})

or is there any other way to send the json model via ajax to backend java program? Can anyone help me with this? Thank you very much:)

regards,

La