我正在尝试将数据发布到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);
});
}
答案 0 :(得分:0)
重新编码代码:函数 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);
}
});