2015-01-07 96 views
5

無法通過AJAX和REST API添加問題。我可以讓它與郵差工作,不幸的是,無法獲得Ajax請求。JIRA Rest API錯誤。無法識別的令牌創建問題

我創建的JSON很好,也是發佈請求。 issuetype是我自己創建的,使用Bug給出了同樣的問題。見創建的JSON對象,我的錯誤和我的代碼: JSON對象(這是來自的console.log片段):

snippet from the console. (I do console.log(jira)

的誤差

0:「無法識別的令牌「fils5poet5 「:期待 '空', '真', '假' 或NaN↵在[來源: [email protected];行:1, 柱:21]」

jira = { 
    fields : { 
     project : { 
     key : "CIC" 
     }, 
     summary : "test", 
     description: "test", 
     issuetype : { 
     name : "Sandbox item" 
     } 
    } 
}; 

console.log(jira); //Also see image at top of this post. 

// Submit to Jira api 
$.ajax({ 
    type : "POST", 
    dataType : "JSON", 
    url : configuration.api_url, 
    beforeSend: function (xhr) { 
     xhr.setRequestHeader ("Authorization", "Basic ItsAWrap!(itworks...)"), 
     xhr.setRequestHeader ("Content-Type", "application/json"); 
    }, 
    data : jira, 
    success : (function(response) { 
//Do something 
}}) 

回答

2

你可以嘗試這樣的事:

jira = { 
    "fields": 
    { 
     "project": 
     { 
      "key": "CIC" 
     }, 
     "summary": data["story.name"], 
     "description": data["story.notes"], 
     "issuetype": { "name": "Sandbox item" } 
    } 
}; 

//THIS BADASS FUNCTION!!! 
jira = JSON.stringify(jira); 

$.ajax({ 
    type : "POST", 
    url : configuration.api_url, 
    dataType : "JSON", 
    async : false, 
    headers: { 
     "Authorization": "Basic YeahSomethingInAWrap", 
     "Content-Type": "application/json", 
     "Accept": "application/json", 
     "Cache-Control": "no-cache" 
    }, 
    data : jira, 
    success : (function(response) { 
     // Hide loader 
     l.removeClass("show"); 

     // Alert Success Message 
     alert("Melding succesvol ontvangen, bedankt!"); 

     // Close dialog 
     $(".chrome-extension-dialog a.close").trigger("click"); 

    }) 
}); 
4

您需要JSON.stringify您的JIRA變量在發送前。

相關問題