2011-01-11 10 views
8

startDateTime & endDateTime Eğer var olan bu çizgisinde dateTime değerler:JQuery ajax() çağrısında birden çok JavaScript veri değişkeni nasıl iletilir?

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) 

Nasıl aşağıda ajax çağrısına hem startDateTime & endDateTime geçmek?

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

}, 

cevap

11

Dene:

data: { 
    start: startDateTime, 
    end: endDateTime 
} 

Bu 'start' ve kullanabileceğiniz sunucu üzerinde 'sonu' istek parametreleri yaratacaktır.

{...}, object literal olup, bu, nesne oluşturmanın kolay bir yoludur. .ajax işlevi, nesneyi alır ve özelliklerini (bu durumda, 'başlangıç' ve 'son'), sunucuya gönderilen HTTP isteğinde özellikler olarak ayarlanan anahtar/değer çiftlerine çevirir.

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

JSON gösterimde değerlerini geçirebilirsiniz:

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

bu çalıştı ... tnx –

1

Deneyin:

verileri: JSON.stringify ({başlatmak: startDateTime, son: endDateTime})

0

Bu tarifhamede,

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 
    } 

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