Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

If startDateTime & endDateTime have are dateTime values along the lines of this:

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 & endDateTime to the ajax call 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
        }
    });         

},
like image 344
Tony Gilroy Avatar asked Jan 11 '11 22:01

Tony Gilroy


2 Answers

Try:

data: {
    start: startDateTime,
    end: endDateTime
}

This will create request parameters of 'start' and 'end' on the server that you can use.

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

like image 55
Rob Hruska Avatar answered Oct 11 '22 17:10

Rob Hruska


data: {
    startDateTime : "xxx",
    endDateTime : "yyy"
}
like image 20
Cesar Avatar answered Oct 11 '22 17:10

Cesar