我使用 Zendesk API 文档中的标准示例:
$(document).ready(function () {
var subject = "Test ticket #ABC";
var body = "This is test ticket #ABC";
$.ajax({
url: 'https://tmstest.zendesk.com/api/v2/tickets.json',
contentType: 'application/json',
type: 'POST',
beforeSend: function (xhr) {
var auth = "Basic " + $.base64.encode("email@gmail.com/token:XXXX");
xhr.setRequestHeader("Authorization", auth);
},
data: JSON.stringify({ "ticket": { "subject": subject, "comment": { "body": body } } }),
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 500) {
alert('Internal error: ' + jqXHR.responseText);
} else {
alert('Unexpected error.');
}
}
})
.done(function (data) {
console.log(data.ticket);
})
;
});
它添加了一张票,但我调用了错误部分。textStatus
具有“错误”值,jqXHR.status
为 0,errorThrown
为空字符串。怎么了?