javascript - jQuery JIRA Post 无法在 IE/FF 中工作

标签 javascript jquery ajax jira jira-rest-api

我正在尝试将数据发布到 JIRA,但它似乎只能在 Chrome 中使用。不适用于 IE/FF。请帮忙。我认为这与ajax调用设置有关。不确定我需要什么才能让它发挥作用。

       $('#new_request > footer > input').bind('click', function(e) {
  		
        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);
    

        
      });
  
  
  
    }
 

最佳答案

代码重组:函数CreateJIRATicket取出IF结构,并将contentType更改为使用默认值(为什么是“application/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);
    }
});

关于javascript - jQuery JIRA Post 无法在 IE/FF 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32958688/

相关文章:

javascript - CakePHP 动态表单输入

javascript - 如何在浏览器控制台中使用单行代码多次执行javascript命令?

javascript - 在 kineticJS 中翻转图像?

javascript - 如何将 css 元素更改添加到此 jquery 库中的 onclick 事件?

javascript - 单击静音按钮时如何将音量 slider 上的输入类型范围重置为 0?

javascript - cy.url 未按预期返回字符串

jQuery .slideUp 在 .animate 之前执行

php - 你能有一个设置为数组的 PHP $_POST 变量吗?

javascript - 在更高的数字上显示元素

javascript - 淡入稍后加载的屏幕外元素