function ajax(url, method, data, f){ var xhr; try{ xhr=new XMLHttpRequest(); } catch (e){ try{ xhr=new ActiveXObject('Msxml2.XMLHTTP'); } catch (e){ try{ xhr=new ActiveXObject('Microsoft.XMLHTTP'); } catch (e){ alert("Don't support!"); return false; } } } xhr.onreadystatechange = f; xhr.open(method, url, false); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.send(data); }; ajax('/login.php', 'POST', 'username=username&password=password', function f(){ if(this.readyState==4){ if(this.status=200){ eval('var obj=' + this.responseText + ';'); alert(obj.success); } else{ alert('Network interactive failure!'); } } });