function testing() { string = "bla=bla&bla=bla"; xhSend4(string); if (resposta == "1") { code, code, code... } else if (resposta == "2") { code, code, code... } else if (resposta == "3") { code, code, code... } else { code, code, code... } } function xhSend4(string){ function createXMLHttpRequest() { try{ return new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){} try{ return new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){} try{ return new XMLHttpRequest(); }catch(e){} alert("XMLHttpRequest not supported"); return null; } var xhReq = createXMLHttpRequest(); xhReq.open("post","index.php",true); xhReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhReq.onreadystatechange = function do_readyStateChange() { if (xhReq.readyState == 4) { resposta = xhReq.responseText; alert(resposta); return resposta; } } xhReq.send(string); }