• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in refreshing

 
priya pratheepp
Ranch Hand
Posts: 59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

for refreshing the page I am using ajax .When i call it in html it is working.when i call it in jsp i am not getting result.I can't able to understand where is the problem please help.

line where calling the ajax is

out.println("<Select name=\"staff_grade\" onChange=\"showCustomer(this.value)\" >");

SCRIPT PROGRAM IS

var xmlHttp

function showCustomer(str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="report_to.jsp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}


JSP PROGRAM IS report_to.jsp


<%@ page language="java" import="java.io.*,java.text.*,java.sql.*,java.util.*,gsis.*"%>


<%

try
{
String reportTO= request.getParameter("q");
int reportTOI=Integer.parseInt(reportTO);

out.println("<table>");
while(reportTOI > 0)
{
reportTOI=reportTOI-1;
out.println("<tr><td>"+reportTOI+"</td></tr>");

}
}catch(Exception e)
{

out.println("Problem in connection" + e.toString());
}



out.println("</table>");

%>


please help...urgent one

thanks in advance
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
  • GET is made to cache, post is not. So the call is going what http get requests are designed to do.
  • You are not setting no cache headers on your jsp page.
  • open should come before onreadystatechange
  • You are not checking the status code of 200
  • you can set the is moified header




  • As Bear and I always say. It is better to use a library for Ajax code than to write your own. There are tons of quirks in the Ajax code that you are not taking into account. I only listed a couple above, but there are a lot more.

    Eric
     
    priya pratheepp
    Ranch Hand
    Posts: 59
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Eric,

    Thank you for the valuable suggestions.

    I am new to AJAX and I must use this to refresh my page today.

    *****library for Ajax code ****

    Can you tell me any library code to my purpose.When I select a value in select button then next select button should display the data corresponds to the previous selected item.

    Once again thanks
    Priya
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64181
    83
    IntelliJ IDE Java jQuery Mac Mac OS X
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I generally recommend one of Prototype or jQuery as general-purpose JavaScript libraries with good Ajax APIs. These days, I'm using jQuery personally.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic