aspose file tools*
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
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: 61773
        
      67

    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]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: problem in refreshing