2015-10-05 74 views
1

我想發佈數據給JIRA,它似乎只在Chrome中工作。在IE/FF中不起作用。請幫忙。我認爲這與ajax呼叫設置有關。不知道我需要什麼讓這個工作。jQuery JIRA發佈不工作在IE/FF

 $('#new_request > footer > input').bind('click', function(e) { 
 
    \t \t 
 
     var subjects = $("#request_subject").val(); 
 
     var descriptions = $("#request_description").val(); 
 
     var attachments = $(".upload-link").attr('href'); 
 
     var cust1 = $("#request_custom_fields_27736417").val(); 
 
     var cust2 = $("#request_custom_fields_27745068").val(); 
 
     var cust3 = $("#request_custom_fields_27736427").val(); 
 
     var cust4 = $("#request_custom_fields_27745078").val(); 
 
     var cust5 = $("#request_custom_fields_27736437").val(); 
 
     var cust6 = $("#request_custom_fields_27638038").val(); 
 
     var cust7 = $("#request_custom_fields_27638118").val(); 
 
     var cust8 = $("#request_custom_fields_27632077").val(); 
 
     var cust9 = $("#request_custom_fields_27632087").val(); 
 
      
 
     if (subjects !== null || descriptions !== null){ 
 
      
 
       function CreateJIRATicket(summary,description, custom1,custom2,custom3,custom4,custom5,custom6,custom7,custom8,custom9,custom10) { 
 
    
 
      var JIRAusername = "YouruserName"; 
 
      var JIRApassword = "YourPassword"; 
 
      
 
    
 
      
 
      var jsondata = {"fields": 
 
     { "project":{ "key": "ZDI"}, 
 
     "summary": summary, 
 
     "description":description, 
 
     "issuetype": {"name": "Story" }, 
 
     "customfield_11200" : custom1, 
 
     "customfield_11201" : custom2, 
 
     "customfield_11202" : custom3, 
 
     "customfield_11203" : custom4, 
 
     "customfield_11204" : custom5, 
 
     "customfield_11205" : custom6, 
 
     "customfield_11206" : custom7, 
 
     "customfield_11207" : custom8, 
 
     "customfield_11208" : custom9, 
 
     "customfield_11209" : custom10 
 
     } 
 
      }; 
 

 
      $.ajax({ 
 
       type: "POST", 
 
       
 
       crossDomain: true, 
 
       contentType:"application/json; charset=utf-8", 
 
       dataType: "json", 
 
       username: JIRAusername, 
 
       password: JIRApassword, 
 
       data: JSON.stringify(jsondata), 
 
       url: "https://jira.yourdomain.com/rest/api/2/issue", 
 
       xhrFields: { 
 
        "withCredentials": true 
 
       }, 
 
       
 
       success: function (ticket){ 
 
        console.log('Page saved!', ticket); 
 
       }, 
 
       error : function(xhr, errorText){ 
 
        console.log('Error '+ xhr.responseText); 
 
       } 
 
    
 
    
 
    
 
      })//end ajax post JIRA 
 
    
 
     } 
 
     
 
    
 

 

 
    } 
 
    
 

 

 

 
      
 
      
 
      CreateJIRATicket(subjects, descriptions, cust1, cust2, cust3, cust4, cust5, cust6, cust7, cust8, cust9, attachments); 
 
    
 

 
     
 
     }); 
 
    
 
    
 
    
 
    } 
 

+0

你得到的錯誤是什麼?該跨域交換機看起來很可疑。 – Robert

回答

0

代碼重組:函數CreateJIRATicket取出IF結構,並改變的contentType使用默認的(爲什麼 「應用/ JSON」?)。試試這個:

function CreateJIRATicket(summary,description, custom1,custom2,custom3,custom4,custom5,custom6,custom7,custom8,custom9,custom10) { 
    var JIRAusername = "YouruserName"; 
    var JIRApassword = "YourPassword"; 
    var jsondata = {"fields": 
     { "project":{ "key": "ZDI"}, 
     "summary": summary, 
     "description":description, 
     "issuetype": {"name": "Story" }, 
     "customfield_11200" : custom1, 
     "customfield_11201" : custom2, 
     "customfield_11202" : custom3, 
     "customfield_11203" : custom4, 
     "customfield_11204" : custom5, 
     "customfield_11205" : custom6, 
     "customfield_11206" : custom7, 
     "customfield_11207" : custom8, 
     "customfield_11208" : custom9, 
     "customfield_11209" : custom10} 
    }; 
    $.ajax({ 
     type: "POST", 
     crossDomain: true, 
     contentType:"application/x-www-form-urlencoded; charset=UTF-8", 
     dataType: "json", 
     username: JIRAusername, 
     password: JIRApassword, 
     data: JSON.stringify(jsondata), 
     url: "https://jira.yourdomain.com/rest/api/2/issue", 
     xhrFields: {"withCredentials": true}, 
     success: function (ticket){console.log('Page saved!', ticket);}, 
     error : function(xhr, errorText){console.log('Error '+ xhr.responseText);} 
    })//end ajax post JIRA 
} 

$('#new_request > footer > input').bind('click', function(e) { 
    var subjects = $("#request_subject").val(); 
    var descriptions = $("#request_description").val(); 

    if (subjects !== null || descriptions !== null){ 
     var attachments = $(".upload-link").attr('href'); 
     var cust1 = $("#request_custom_fields_27736417").val(); 
     var cust2 = $("#request_custom_fields_27745068").val(); 
     var cust3 = $("#request_custom_fields_27736427").val(); 
     var cust4 = $("#request_custom_fields_27745078").val(); 
     var cust5 = $("#request_custom_fields_27736437").val(); 
     var cust6 = $("#request_custom_fields_27638038").val(); 
     var cust7 = $("#request_custom_fields_27638118").val(); 
     var cust8 = $("#request_custom_fields_27632077").val(); 
     var cust9 = $("#request_custom_fields_27632087").val(); 
     CreateJIRATicket(subjects, descriptions, cust1, cust2, cust3, cust4, cust5, cust6, cust7, cust8, cust9, attachments); 
    } 
});