使用Odata在数据库中创建新行

时间:2015-12-07 10:13:24

标签: sap sapui5

我有一个指向数据库中表的OData服务。我想根据用户的详细信息在表格中输入新记录。

我使用的是.create方法,但数据似乎没有输入到表格中。

oView=this.getView();
var df = {};
var name = oView.byId("__input3").getValue();  
var goal = oView.byId("__area0").getValue();

df.NAME = name;
df.GOAL = goal;
df.TYPE = "type";
df.THEME = "Theme";

var oModel1= new sap.ui.model.odata.ODataModel("/GDH_OData/services/df.xsodata/");
oModel1.create('/Df', df, null, function() {
    alert("SUCCESS");
}, function() {
    alert("FAIL");
});

请帮助我出错的地方

2 个答案:

答案 0 :(得分:0)

you're not giving a lot of info, here...

  • what is the result of your create call ? SUCCESS or FAIL ? if the later, what is the error message returned ? the following error function can help you on this

    function(error) {
    var message = $(error.response.body).find('message').first().text();
    console.log(message);
    alert(message);
    }

  • Is the creation code in the backend called (if you put an external breakpoint in your service, do you get the debugger ?) if so, what is the result of debugging step-by-step ?

edit
if there is a "forbidden" response, then you should check the result of transaction su53 for the user. You'll probably have a failed autorization. Then it's just adding the service to your role autorisation.

PS : its better to add your answer to my questions(s) in your question, under a "edit" or "more information" than to put it as another answer. Thus there is only one place to check for the whole problem.

regards

答案 1 :(得分:-1)

结果是失败,错误是“无法加载资源:服务器响应状态为403(禁止)”