如何在jQuery ajax()调用中传递多个JavaScript数据变量?
如果如何在jQuery ajax()调用中传递多个JavaScript数据变量?,jquery,ajax,parameter-passing,Jquery,Ajax,Parameter Passing,如果startDateTime和endDateTime有如下日期时间值: 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) 如何将startDateTime和endDateTime传递给下面的ajax调用 eventNew : function(calEvent, event) { var sta
startDateTime
和endDateTime
有如下日期时间值:
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)
如何将startDateTime
和endDateTime
传递给下面的ajax调用
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
}
});
},
尝试:
这将在服务器上创建您可以使用的“开始”和“结束”请求参数
{…}
是一种创建对象的简单方法。函数获取对象并将其属性(在本例中为“开始”和“结束”)转换为键/值对,这些键/值对被设置为发送到服务器的HTTP请求的属性。您可以通过JSON表示法传递值:
data: {
startDateTime : "xxx",
endDateTime : "yyy"
}
data: {startDateTime: 'value here ', endDateTime: 'value here '}
试试看:
数据: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)}, //finish with **,**
type: 'POST',
success: function(response)
{
// do something with response
}
});
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
}
});
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
}
});