Ola pessoal estou com uma duvida em AJAX;
não consigo fazer um refesh na pagina sem qe ela seja atualizada … ao clicar no submit não traz nada;
sou novo não muita coisa;
esse é o meu codigo;
JSP
<script type="text/javascript">
function getXMLObject() //XML OBJECT
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // For Old Microsoft Browsers
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); // For Microsoft IE 6.0+
}
catch (e2) {
xmlHttp = false; // No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers
}
return xmlHttp; // Mandatory Statement returning the ajax object created
alert("ok");
}
var xmlhttp = new getXMLObject();
function ajaxFunction(){
if(xmlhttp){
var nome = document.getElementById("nomeProjeto");
xmlhttp.open("POST", "getname", true);
xmlhttp.onreadystatechange = handleServerResponse;
alert("response");
xmlhttp.send("nameProjeto=" + nome.value);
}
}
function hadleServerResponse(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
document.atividadeForm.massage.value=xmlhttp.responseText;
}
else{
alert("Ocorreu um Erro");
}
}
}
</script>
<form name="atividadeForm" action="getname" method="POST">
Nome do Projeto:<input type="text" name="nomeProjeto" id="nomeProjeto" onkeyup="ajaxFunction();"/>
PROJETO<br/><br/> <div id= "message"></div>
<input type="button" value="Buscar" onclick="ajaxFunction()"/><br/><br/>
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String nome = null;
PrintWriter out = response.getWriter();
if(request.getParameter("nomeProjeto") != null){
nome = request.getParameter("nomeProjeto");
}
else{nome = "";}
out.println("ajax successefully"+nome);
}
alguem pode me ajudar ???
Grato