JavaScript Nodejs, express, Ajax: Function triggers only Six Times node js express ajax tutorial,node js express ajax request,

using nodejs and express I'm trying to trigger a js function which contains a simple console log. Sadly the function only triggers 6 times and freezes for a while. After a minute or two all the button clicks which where clicked during the "frozen time" triggers at once. It happens always after 6 times of pressing a button.

index.html -> button
client side -> jquery function that triggers an Ajax post function
server.js -> contains the express function which triggers the console log

index.html

<input type="button" id="car" value="drive"/>

clientside.js

$('#car').click(function(){

   $.ajax({
      type:'POST',
      url: url + '/drive'
   });

});

server.js

var app = express();

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

   console.log('Car starts driving');

});

What am I doing wrong? Any tips how I can improve my code?

Thank You

Answer:1

Your server code should return statement:

app.post('/drive', function(req, res){
   console.log('Car starts driving');
   res.sendStatus(sendStatus)
});

sendStatus details

Good practice is to disable the button after clicking, and then enable it after the response comes back:

//Disable button

$.ajax({
    url: url + '/drive'        
    type: 'POST',        
    data: {},
    success: function(data){
        //Enable button
    },
    error: function(data){
        //Enable button
    }
});
Answer:2

My question has two parts here: I have created an Instagram clone and would like to be able to click on each individual image and have a like feature. The way that I currently have this set up is by ...

My question has two parts here: I have created an Instagram clone and would like to be able to click on each individual image and have a like feature. The way that I currently have this set up is by ...

How can I localize current day and month (without year) in moment.js? What I want is exactly the output of moment().format('LL') but without the year part. Consider the following example: moment()....

How can I localize current day and month (without year) in moment.js? What I want is exactly the output of moment().format('LL') but without the year part. Consider the following example: moment()....

I have been working on a function that loops through a JSON object recursively, and want to use each key it finds as the class value of an element to change the .text value of that element in jQuery. ...

I have been working on a function that loops through a JSON object recursively, and want to use each key it finds as the class value of an element to change the .text value of that element in jQuery. ...

  1. join array values javascript
  2. join array values python
  3. join array values c#
  4. join array values powershell
  5. join array values php
  6. join array values
  7. join array values jquery
  8. join array values java
  9. join array values js
  10. twig join array values
  11. php join array values into string
  12. javascript join array values to string
  13. typescript join array values
  14. postgresql join array values
  15. postgres join array values
  16. bash join array values
  17. join two array values in php
  18. vba join array values
  19. powershell join array values to string
  20. perl join array values

Is there an elegant way (without a for loop) to create a sequential array in Javascript which starts from a certain number and has a certain numbers of items. for example: Start from 2017 and has 4 ...

Is there an elegant way (without a for loop) to create a sequential array in Javascript which starts from a certain number and has a certain numbers of items. for example: Start from 2017 and has 4 ...