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 sta开发者_运维百科rtDateTime
& 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
}
});
},
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.
data: {
startDateTime : "xxx",
endDateTime : "yyy"
}
You can pass the values in JSON notation:
data: {startDateTime: 'value here ', endDateTime: 'value here '}
Try it:
data: JSON.stringify({ start: startDateTime, end: endDateTime })
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
}
});
in the 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
}
});
精彩评论