I am unable to post the data to the server and getting a timeout error. Please see the code below:
Client side script:
$(document).ready(function(){
$('#form1').on('submit',function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "/",
timeout: 2000,
data : JSON.stringify({ image: "yo", text: "apples" }),
dataType : 'json',
success: function(data) {
alert('Success!')
},
error: function(jqXHR, textStatus, err) {
alert('text status '+textStatus+', err '+err)
}
});
})
})
Server side script :
app.use(bodyParser.json());
app.post('/', function (req, res){
console.log(req.body);
console.log('req received');
});
On the server I am seeing the output as
APP STARTED ON PORT - 3000
{}
req received
Can you please guide me for why I am unable to receive the data ? Thank you in advance.