我想使用HTTP GET方法來檢索後面這是JSON格式顯示在data_id
以下基礎數據這裏是我的JSON數據HTTP GET方法用於JSON數據的
{
"data_id": "61dffeaa728844adbf49eb090e4ece0e",
"file_info": {
"display_name": "samplefile.txt",
"file_size": 81035,
"file_type": "text/plain",
"file_type_description": "ASCII text",
"md5": "c05017f68343a5257fc3c0db72aa58dc",
"sha1": "ba46b945f408cc729458380350b4e78f61741c81",
"sha256": "8805777d2d561255edcb499f7445ef0216b75737bacb6bc6665dbf9830272f53",
"upload_timestamp": "2015-08-14T12:46:59.360Z"
},
"scan_results": {
"data_id": "61dffeaa728844adbf49eb090e4ece0e",
"progress_percentage": 100,
"scan_all_result_a": "No Threat Detected",
"scan_all_result_i": 0,
"scan_details": {
"Engine1": {
"def_time": "2015-08-13T09:32:48.000Z",
"location": "local",
"scan_result_i": 0,
"scan_time": 1,
"threat_found": ""
},
"Engine2": {
"def_time": "2015-08-10T00:00:00.000Z",
"location": "local",
"scan_result_i": 0,
"scan_time": 3,
"threat_found": ""
}
},
"start_time": "2015-08-14T12:46:59.363Z",
"total_avs": 2,
"total_time": 389
},
"process_info": {
"post_processing": {
"actions_ran": "",
"actions_failed": "",
"converted_to": "",
"copy_move_destination": "",
"converted_destination": ""
},
"progress_percentage": 100,
"user_agent": "webscan",
"profile": "File scan",
"result": "Allowed",
"blocked_reason": "",
"file_type_skipped_scan": false
}
}
根據網站文檔,我可以通過http://www.example.com/file/ {data_id}檢索JSON數據。但我的JavaScript沒有這樣做,我沒有得到任何迴應我的網頁瀏覽器。可能我知道是我的JavaScript有一些問題來檢索JSON數據?我有點新的如何JSON數據工作
<html>
<head>
<script>
function formShow()
{
var getData = function(url, callback) {
var request = new XMLHttpRequest();
request.open('get', url, true);
request.responseType = 'json';
request.onload = function() {
var status = request.status;
if (status == 200) {
callback(null, request.response);
} else {
callback(status);
}
};
xhr.send();
};
getData('http://192.168.0.25:8008/file/d81d2e183dbd4303a1ffa6d8388bbd27', function(err, data) {
if (err != null) {
alert('Something went wrong: ' + err);
} else {
alert('Your Json result is: ' + data.result);
result.innerText = data.result;
}
});
}
</script>
</head>
<body>
<form method="POST" action="" name="myForm">
<input type="submit" value="Show" onclick="formShow()">
</form>
<div id="result" style="color:red"></div>
</body>
</html>
你在瀏覽器的開發者工具控制檯中看到什麼錯誤? –
'getJSON'在'jQuery'中定義,所以如果你想用'getJSON'使用'jQuery.getJSON'作爲起點,請添加jQuery。 – zmii
您也可以使用原生'fetch' API,如https://davidwalsh.name/fetch所述,如果您不想使用jQuery – zmii