This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes problem in refreshing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "problem in refreshing" Watch "problem in refreshing" New topic
Author

problem in refreshing

priya pratheepp
Ranch Hand

Joined: Apr 02, 2008
Posts: 59
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
  • 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

    Joined: Apr 02, 2008
    Posts: 59
    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

    Joined: Jan 10, 2002
    Posts: 60766
        
      65

    I generally recommend one of Prototype or jQuery as general-purpose JavaScript libraries with good Ajax APIs. These days, I'm using jQuery personally.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
     
     
    subject: problem in refreshing
     
    Similar Threads
    How to display value in combo box using AJAX
    Regading getElementById
    Can AJAX helps me to do that
    Using AJAX in Struts.... need steps to Implement..
    problem with sending # character through ajax