我有一个在用户单击表单上的“提交”时触发的函数。除custom_fields外,所有内容都将提交给 freshdesk 。
我正在使用带有控制器的 Angular 1.4,所以 ctrl 是我的控制器。这是我的代码:
function postTicket() {
var formdata = new FormData();
var customFields = {
"serial_number": ctrl.newTicket.serialnumber
};
customFields = JSON.stringify(customFields);
formdata.append('description', ctrl.newTicket.description);
formdata.append('subject', ctrl.newTicket.subject);
formdata.append('type', ctrl.newTicket.type);
formdata.append('email', ctrl.newTicket.email);
formdata.append('custom_fields', customFields);
formdata.append('status', 2); // open
formdata.append('priority', 1); // low
supportResource.postTicket(formdata).then(
results => {
console.log('it worked! ', results);
ctrl.formSent = true;
},
error => {
console.log('something went wrong. ', error);
});
}
这是 supportResource 代码:
function postTicket(ticket) {
return $q(function(fulfill, reject) {
$http({
url: `https://${MYACCOUNT}.freshdesk.com/api/v2/tickets`,
method: 'POST',
headers: {
'Authorization': 'Basic ' + btoa(MYKEY),
'Content-Type': undefined
},
data: ticket
}).then(
results => {
fulfill(results.data);
},
error => reject(error));
});
}
我已经按照这里的例子: https ://github.com/freshdesk/fresh-samples/blob/master/jquery/create_ticket_with_attachment.html
我也看到了这个: https: //support.freshdesk.com/support/solutions/articles/216548-create-and-update-tickets-with-custom-fields-using-api
但这个例子是使用 CURL,我不知道如何使用 FormData() http://developer.mozilla.org/en-US/docs/Web/API/FormData发送数据