ajax("get","1.get.php","username=jh&password=123",function(data){ // alert(data); var data = JSON.parse(data); }); // function ajax(method,url,data,fn){ // // try{ // var xhr = new XMLHttpRequest(); // }catch(e){ // var xhr = new ActiveXObject(); // } // if( method == "get" && data) // { // url += '?'+data; // } // xhr.open(method,url,true); // if(method == 'get') // { // xhr.send(); // }else{ // // xhr.send(data); // } // // // // xhr.onreadystatechange = function(){ // if(xhr.readyState == 4) // { // if(xhr.status == 200) // { //// alert(xhr.responseText) // fn && fn(xhr.responseText); // // }else{ // alert("错误 Err:"+xhr.status); // } // } // } // }