Monday, 29 May 2017

Failed to load resource: 404 (Not Found) - Data are not passed to the backend

I get 404 error when i read and send those data to the back-end.

enter image description here

i Have a MEAN web app ..below i have added wriiten codes

Controller

$scope.addFileContents= function(readDetails)
{
var lines = readDetails.split('\n');
for(var line = 0; line < lines.length-1; line++){
var logFileContent = ""; 
var linesSpace = lines[line].split(' ');
for(var y=3;y <= linesSpace.length-1;y++){
logFileContent +=linesSpace[y];
logFileContent += " ";
  }   
var event = {
dat: linesSpace[0],
tim: linesSpace[1],
details: logFileContent,  
 };
 Event.ReadUploadFile(event)
  .success(function () {
      $scope.status = 'Reading the selected file';          
  })
  .error(function (error) {
      $scope.status = 'Unable to insert data: ' ;
  });

} }

Service

  ReadUploadFile : function(event) {
        return $http.post('/api/filesReadUpload', event);
        $window.location.reload();
    },

Route

app.post('/api/filesReadUpload', function(req, res) {

    var events=new filesReadUpload({

        dat:req.body.dat,
        details:req.body.details,
        tim:req.body.tim,
             });

    events.save(function(err) {
        if (err)
        return res.send(err);

        res.json({    message: 'Read file!'  });
              });
        });

model

var mongoose = require('mongoose');
var Schema  = mongoose.Schema;
var filesUpload= new Schema({

_id:String,
dat:String,
details:String,
tim:String,

},
{
versionKey: false
});
module.exports = mongoose.model('filesReadUpload',filesUpload);

can anyone suggest a way to solve this issue? Thanks



via Shan

No comments:

Post a Comment