Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jQuery ajax()调用中传递多个JavaScript数据变量?_Jquery_Ajax_Parameter Passing - Fatal编程技术网

如何在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 
     }
});