下面的示例代码是 Freshdesk ( https://github.com/freshdesk/fresh-samples ) 提供的 jquery 示例。我插入我的 url 和 api 密钥,它就可以工作了。
我想对此进行自定义,以便当按下读取按钮时,输出的 json 对象数据是可点击的,特别是票证“主题”值。单击此按钮将关闭工单。
我不知道从哪里开始,最终只想在 ajax 调用后有一个可点击的值。单击以关闭工单的操作将是我需要解决的另一件事。
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(
function() {
var yourdomain = 'yourdomain'; // Your freshdesk domain name. Ex., yourcompany
var api_key = 'API_KEY'; // Ref: https://support.freshdesk.com/support/solutions/articles/215517-how-to-find-your-api-key
$.ajax(
{
url: "https://"+yourdomain+".freshdesk.com/api/v2/tickets",
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": "Basic " + btoa(api_key + ":x")
},
success: function(data, textStatus, jqXHR) {
$('#result').text('Success');
$('#code').text(jqXHR.status);
$('#response').html(JSON.stringify(data, null, "<br/>"));
},
error: function(jqXHR, tranStatus) {
$('#result').text('Error');
$('#code').text(jqXHR.status);
x_request_id = jqXHR.getResponseHeader('X-Request-Id');
response_text = jqXHR.responseText;
$('#response').html(" Error Message : <b style='color: red'>"+response_text+"</b>.<br/> Your X-Request-Id is : <b>" + x_request_id + "</b>. Please contact support@freshdesk.com with this id for more information.");
}
}
);
}
);
});
</script>
</head>
<body>
<button>Read</button>
<br/></br>
<table cellspacing = '10'>
<tr>
<td> <b>Result</b></td>
<td> <div id = 'result'></div> </td>
</tr>
<tr>
<td> <b>Code</b></td>
<td> <div id = 'code'></div> </td>
</tr>
<tr>
<td> <b>Response</b></td>
<td> <div id = 'response'></div> </td>
</tr>
</table>
</body>
</html>