嗨我正在從API請求數據,我想將結果添加到具有特定ID的Div。 它工作得很好,但當我試圖爲它創建一個自定義函數時,它停止工作。JSON API請求的自定義函數
它與我的fullrequest變量有關。但我不知道如何去做。
我的HTML:
<script>
OctoGET0('GET', '/api/connection', 'current.state' , '#play')
</script>
我的jQuery:
function webAPI(method, location , data, request , id) {
var fullrequest = 'response.'+request;
$.ajax({
url: Url + location ,
type: method,
dataType: 'json',
beforeSend: setHeader,
data: data,
success: (function(response) { $(id).html(fullrequest)})
})
[編輯]
我想申請
{
"current": {
"baudrate": null,
"state": "Closed",
"port": null
},
"options": {
"portPreference": null,
"autoconnect": false,
"baudrates": [
250000,
230400,
115200,
57600,
38400,
19200,
9600
],
"ports": [
"/dev/ttyAMA0"
],
"baudratePreference": null
}
}
一些請求進入更深比2的JSON層。
我想響應是可變的。 這是需要的樣子。 html(response.current.state) –
嗯我不知道什麼即時通訊做錯了,當我適應它在我的js我得到的唯一的迴應是[對象對象] 添加JSON我要求從我的問題的數據 –