Reputation: 5406
this is my server side POST code .before my task saving database im find same data in the database using my unique value as service
but when i run this code console says ReferenceError: service is not defined
what is wrong here?can some one poine me.please
app.post('/collections/:collectionName', function(req, res, next) {
req.collection.findOne({service: service}, function(e, result){
if(result){
res.send{error: "REQUEST ALREADY EXISTS"};
}
else{
req.collection.insert(req.body, {}, function(e, results){
if (e) return next(e)
res.send(results)
});
}
});
})
update----
button.addEventListener('click', function(e) {
var service_ = service.value;
var amount_ = amount.value;
var name_ = name.value;
var phone_ = phone.value;
var reminder_ = reminder.value;
if (start_pick < end_pick) {
var jsondata = [{
start_time : new Date(start_pick),
end_time : new Date(end_pick),
service : service_,
amount : amount_,
client_phone : phone_,
client_name : name_,
reminder : reminder_
}];
var xhr = Titanium.Network.createHTTPClient();
xhr.setTimeout(10000);
xhr.open("POST", "http://127.0.0.1:3000/collections/appoinments");
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhr.send(JSON.stringify(jsondata));
xhr.onerror = function() {
Titanium.API.info("Error in connecting to server !!");
alert("Error on connecting to server, Please try again");
};
xhr.onload = function() {
windowPayment.close();
}
Upvotes: 0
Views: 86
Reputation: 19719
The data sent by the POST request will be accessible through req.body
, so the variable you are looking for is req.body.service
. Also, assuming the function req.collection.findOne
uses the property service
of the first argument, you should keep the code as following:
req.collection.findOne({service: req.body.service}, function(e, result){
//...
});
Given that an object {req.body.service: ...}
is invalid.
Upvotes: 1