Client Side Code :
var item = {
product : 'Samsune',
price : 100,
quantity : 1
};
$.ajax({
url: window.location.protocol + "//api.backendless.com/2F753BDA-B766-1ED3-FFDD-979207B88200/v1/files/web/scripts/insta/test.js",
type: "OPTIONS",
data: JSON.stringify({item : item}),
contentType: "application/json",
success: function (result) {
console.log(JSON.stringify(result));
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(xhr.responseText);
console.log(thrownError);
}
});
Server Side Code :
function ShoppingItem( args ) {
args = args || {};
this.___class = 'ShoppingItem';
this.product = args.product || "";
this.price = args.price || 0.0;
this.quantity = args.quantity || 0;
}
exports.run = function ( request, response ) {
var req = JSON.parse(request.body);
var reqItem = req.item;
var item = {"product": "'"+reqItem.product+"'","price":reqItem.price,"quantity":reqItem.quantity};
var shoppingItem = new ShoppingItem(item);
Backendless.Persistence.of( ShoppingItem ).save( shoppingItem, new Backendless.Async(
function( savedItem ) {
response.send( savedItem );
}, function( fault ) {
response.status( 500 ).send( fault );
})
);
};
The above code Executes and also saves data in the database. But it doesn’t return the saved data. I tried to return a string response.send(‘Success’) . Even this does not show up in the response.