How to pass multiple javascript data variables in jQuery ajax () call?

If startDateTime and endDateTime have DateTime values โ€‹โ€‹according to the lines:

 Start: Mon Jan 10 2011 18:15:00 GMT+0000 (GMT Standard Time) End: Mon Jan 10 2011 18:45:00 GMT+0000 (GMT Standard Time) 

How do you pass both startDateTime and endDateTime to call ajax below?

 eventNew : function(calEvent, event) { var startDateTime = calEvent.start; var endDateTime = calEvent.end; jQuery.ajax( { url: '/eventnew/', cache: false, data: /** How to pass startDateTime & endDateTime here? */, type: 'POST', success: function(response) { // do something with response } }); }, 
+8
jquery parameter-passing ajax
source share
6 answers

Try:

 data: { start: startDateTime, end: endDateTime } 

This will create the "start" and "end" request parameters on the server, which you can use.

{...} is an object literal , which is an easy way to create objects. The .ajax function takes an object and translates its properties (in this case, "start" and "end") into key / value pairs that are set as properties of the HTTP request that is sent to the server.

+11
source share
 data: { startDateTime : "xxx", endDateTime : "yyy" } 
+7
source share

You can pass values โ€‹โ€‹in JSON notation:

 data: {startDateTime: 'value here ', endDateTime: 'value here '} 
+3
source share

Try:

: JSON.stringify ({start: startDateTime, end: endDateTime})

+1
source share

in data

 ajax({ url : //your file url finshed with **,** data : {Start: Mon Jan 10 2011 18:15:00 GMT+0000 (GMT Standard Time), End: Mon Jan 10 2011 18:45:00 GMT+0000 (GMT Standard Time)}, //finish with **,** type: 'POST', success: function(response) { // do something with response } }); 
0
source share
 ajax({ url : //your file url finshed with , data : { Start: Mon Jan 10 2011 18:15:00 GMT+0000 (GMT Standard Time), End: Mon Jan 10 2011 18:45:00 GMT+0000 (GMT Standard Time) }, type: 'POST', success: function(response) { // do something with response } }); 
0
source share

Source: https://habr.com/ru/post/650951/


All Articles