如何在jQuery ajax()调用中传递多个JavaScript数据变量?

时间:2021-08-10 15:09:28

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

如果startDateTime和endDateTime的值是dateTime,如:

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?

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

},

6 个解决方案

#1


11  

Try:

试一试:

data: {
    start: startDateTime,
    end: endDateTime
}

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

这将在您可以使用的服务器上创建“start”和“end”的请求参数。

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.

{……}是一个对象文字,它是创建对象的一种简单方法。ajax函数获取对象并将其属性(在本例中是“start”和“end”)转换为键/值对,这些键/值对设置为发送到服务器的HTTP请求上的属性。

#2


7  

data: {
    startDateTime : "xxx",
    endDateTime : "yyy"
}

#3


3  

You can pass the values in JSON notation:

您可以用JSON符号传递值:

data: {startDateTime: 'value here ', endDateTime: 'value here '}

#4


1  

Try it:

试一试:

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

数据:JSON。stringify({start: startDateTime, end: endDateTime})

#5


0  

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 
     }
});

#6


0  

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
    }

});

#1


11  

Try:

试一试:

data: {
    start: startDateTime,
    end: endDateTime
}

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

这将在您可以使用的服务器上创建“start”和“end”的请求参数。

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.

{……}是一个对象文字,它是创建对象的一种简单方法。ajax函数获取对象并将其属性(在本例中是“start”和“end”)转换为键/值对,这些键/值对设置为发送到服务器的HTTP请求上的属性。

#2


7  

data: {
    startDateTime : "xxx",
    endDateTime : "yyy"
}

#3


3  

You can pass the values in JSON notation:

您可以用JSON符号传递值:

data: {startDateTime: 'value here ', endDateTime: 'value here '}

#4


1  

Try it:

试一试:

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

数据:JSON。stringify({start: startDateTime, end: endDateTime})

#5


0  

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 
     }
});

#6


0  

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
    }

});