on 05-01-2013 10:51 PM
Hi,
I have a xsjs script which delete's a record based on the input parameter. If i execute this via a URL, its deleting the record properly.
But when i call from Html page which has a Text field and a submit button, its not deleting the record even though its calling the xsjs.
------------------------------ XSJS Content --------------------------
$.response.contentType = "text/html";
var body='';
var app_id=$.request.parameters.get('app_id');
var query = "delete from Table where application_id='"+app_id+"'";
var conn = $.db.getConnection();
var pstmt = conn.prepareStatement(query);
var updateCount = pstmt.executeUpdate();
body = updateCount.toString();
conn.commit();
$.response.setBody("Number of records updated:"+body);
$.response.status=$.net.http.OK;
------------------------------ End --------------------------
-------------------------- HTML ----------------------
var oButton4 = new sap.ui.commons.Button({
text : "Submit",
style: sap.ui.commons.ButtonStyle.Emph,
press : function(oEvent,oInput1) {
var jURL = '../demo/demo/updateLOG.xsjs';
jQuery.ajax({
url:jURL,
method: 'POST',
dataType:'json',
success: myFunction.onComplete,
error: myFunction.onErrorCall
});
}
}).placeAt("content");
---------------------- END --------------------------
Thanks for the help
NAresh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Naresh
I think the ajax call should not be a POST because you are doing
var app_id=$.request.parameters.get('app_id');
in XSJS, you would need to do
var body = $.request.body.asString();
if you do a HTTP POST.
Anyway, you can do a HTTP GET to get it to work. Although, I thought HTTP DELETE will be more appropriate
press : function(oEvent,oInput1) {
var jURL = '../demo/demo/updateTBLOG.xsjs';
jQuery.ajax({
url:jURL,
data: {app_id : $('#app_id').val()},
type: 'GET',
success: myFunction.onComplete,
error: myFunction.onErrorCall
});
}
Hope this helps
Dennis
Hi Naresh
If you send over two data fields like this (in HTTP POST)
press : function(oEvent,oInput1) {
var jURL = '../demo/demo/updateTBLOG.xsjs';
jQuery.ajax({
url:jURL,
data: {data1 : 'hello', data2: 'world'},
type: 'POST',
success: myFunction.onComplete,
error: myFunction.onErrorCall
});
}
Then I believe that var body = $.request.body.asString() will be
data1=hello&data2=world
You have to parse it yourself.
And the another thing, that Thomas was pointing at
var query = "delete from Table where application_id='"+app_id+"'";
var conn = $.db.getConnection();
var pstmt = conn.prepareStatement(query);
var updateCount = pstmt.executeUpdate();
can be better written as
var query = "delete from Table where application_id=?";
var conn = $.db.getConnection();
var pstmt = conn.prepareStatement(query);
pstmt.setString(1, app_id);
var updateCount = pstmt.executeUpdate();
Thanks
Did you get this working?
I am trying to do a DELETE but I cant get the conn.prepareStatement() work with the delete query. Selecting is fine, updating is fine, but delete does not work. It just gives me the error-Page of the XS Server.
My HANA Version is Rev 48... if you got it working, which Rev do you use?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't see anywhere in your HTML code where you pass the app_id parameter to the service. Shouldn't you be building that into the URL for the AJAX call?
Also please note (although this has nothing to do with your update not working) that you should concatenate variables directly into your SQL statements. This exposes you to the potential for SQL Injection. You should always use parameterized SQL statements instead.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.