Not getting response from Nodejs

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.

Hi Tabish,

Does our sample app for Node.js work in your application?

If i run the sample code from Developer Dashboard. It works perfect i.e

    Saved data reflects in the database, Sends a response after saving.
But when i download the sample code and then run it from my pc,
    Saved data reflects in the database. Does not send a response after saving.

Are you using Standalone Backendless?

No.

What do you mean by running it from your PC?

I downloaded the sample app and ran ‘index.html’ on localhost. Everything worked as expected but i didn’t receive a response.