function post(url,data,success){ data = JSON.stringify(data); var xmlhttp = null; if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); } xmlhttp.open("POST",url,true); xmlhttp.setRequestHeader("Content-type", "application/json;charset=UTF-8");//www-form-urlencoded xmlhttp.overrideMimeType('audio/wav'); xmlhttp.responseType = "blob"; xmlhttp.timeout = 30000; xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4) { if (xmlhttp.status == 504 ) { console.log("服务器请求超时.."); error(); xmlhttp.abort(); }else if(xmlhttp.status == 200){ // console.log(typeof xmlhttp.response); success(xmlhttp); } xmlhttp = null; } } xmlhttp.ontimeout = function () { console.log("客户端请求超时.."); error(); } xmlhttp.send(data); // timeout function error(){ alert('连接超时,请刷新重试!') } }