2017-10-21 81 views
0

我想弄清楚如何使一個AJAX調用baikal服務器做GET,POST,OPTIONS,PROPFIND,PROPPATCH,REPORT,PUT,MOVE,DELETE,LOCK,UNLOCK使用sabreDAV AJAX呼叫貝加爾共享日曆

我已經使用此代碼here並得到它的工作,但我想我只是不知道如何做一個適當的Ajax調用。

我做同一個域裏面的呼籲避免現在跨域問題。我已經使用CalDavZAP之前,我可以看到他們撥打電話使用AJAX,但我只是無法得到,甚至看着他們的代碼後,它的工作。

我已經試過

var content = 'BEGIN:VCALENDAR VERSION:2.0 CALSCALE:GREGORIAN BEGIN:VEVENT CREATED:20171020T123121Z LAST-MODIFIED:20171020T220236Z DTSTAMP:20171020T220236Z UID:m54url1l-6xwy-snnp-rg0h-7yl5kgsfbadg SUMMARY:this is new TRANSP:OPAQUE CLASS:PUBLIC DTSTART;VALUE=DATE:20171025 DTEND;VALUE=DATE:20171026 END:VEVENT PRODID:-//Inf-IT//CalDavZAP 0.13.1//EN END:VCALENDAR'; 

$.ajax({ 
    type: 'PUT', 
    url: 'http://cal.domain.ca/cal.php/calendars/user/default/crazychars.ics', 
    beforeSend: function(req) { 
    req.setRequestHeader('Prefer', 'return=representation'); 
    req.setRequestHeader('If-None-Match', '*'); 
    }, 
    username:'username', 
    password:'password', 
    contentType: 'text/calendar', 
    processData: true, 
    data: content, 
    dataType: 'text', 
    success: function(data){ 
    console.log(data); 
    }, 
    error: function(){ 
    console.log(data); 
    event.preventDefault(); 
    } 
});//end of AJAX 

嘗試了很多東西上面,現在有415(不支持的媒體類型)返回後。我曾嘗試不同類型的contentType和額外的頭,沒有更好的結果。搜索互聯網後,我不知道做什麼。貝加爾網站不提供提交從我看過所在服務器的例子。

這裏是一些請求/響應頭

Response Headers 
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre- 
check=0 
Connection:Keep-Alive 
Content-Type:application/xml; charset=utf-8 
Date:Sat, 21 Oct 2017 11:44:12 GMT 
Expires:Thu, 19 Nov 1981 08:52:00 GMT 
Keep-Alive:timeout=5, max=98 
Pragma:no-cache 
Server:Apache/2.4.6 
Transfer-Encoding:chunked 
X-Powered-By:PHP/5.6.31 
X-Sabre-Version:3.1.3 

Request Headers 
Accept:text/plain, */*; q=0.01 
Accept-Encoding:gzip, deflate 
Accept-Language:en,fr;q=0.8 
Authorization:Basic Z3N0bG91aXM6R3N0bG91aXM3OA== 
Cache-Control:max-age=0 
Connection:keep-alive 
Content-Length:345 
Content-Type:text/calendar 
Cookie:PHPSESSID=fqc0ctuskfv0cgaqeiq196gtf4; _ga=GA1.2.519255846.1496415686 
Host:cal.smbservices.ca 
If-None-Match:* 
Origin:http://cal.domain.ca 
Prefer:return=representation 
Referer:http://cal.domain.ca/ 
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36 
X-Requested-With:XMLHttpRequest 

回答

0

我的問題是在我的內容變量。爲了使具有良好的格式,每與\ r \ n至完成所需的線Ajax調用

var content = 'BEGIN:VCALENDAR\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nBEGIN:VEVENT\r\nCREATED:20171020T123121Z\r\nLAST-MODIFIED:20171020T220236Z\r\nDTSTAMP:20171020T220236Z\r\nUID:m54url1l-6xwy-snnp-rg0h-7yl5kgsfbadg\r\nSUMMARY:superman\r\nTRANSP:OPAQUE\r\nCLASS:PUBLIC\r\nDTSTART;VALUE=DATE:20171030\r\nDTEND;VALUE=DATE:20171030\r\nEND:VEVENT\r\nPRODID:-//Inf-IT//CalDavZAP0.13.1//EN\r\nEND:VCALENDAR';