// 方式一 var url = "http://127.0.0.1:19196/openDevice"; var time = 5000; var timeout = false; var request = new XMLHttpRequest(); var timer = setTimeout(function() { timeout = true; request.abort(); }, time); request.open("GET", url, true); request.onreadystatechange = function() { if (request.readyState !== 4) { return; } if (timeout) { dorado.MessageBox.alert("out"); return; } clearTimeout(timer); if (request.status === 200) { callback(request.responseText); } }; request.send(null); // 方式二 var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://127.0.0.1:19196/OpenDevice', true); // xhr.withCredentials = true; // 如果需要的话 xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { console.log(JSON.parse(xhr.responseText)); } }; xhr.send();