ajax call to servlet puzzler

Posted by vector on Stack Overflow See other posts from Stack Overflow or by vector
Published on 2010-02-18T03:56:44Z Indexed on 2010/03/25 23:43 UTC
Read the original article Hit count: 444

Filed under:
|
|
|

Greetings!

I'm having a problem getting a text value of a captcha from a servlet through ajax call.

When my captcha gets created, its text value is written to session, but after refreshing the image itself though ajax call, I only get one old value of the text.

Refreshing the image itself works ok, but I'm stuck getting the correct values from the session on subsequent call.

On page reload I get both the new image and its new text value, no joy with ajax though.

This works great for the image refresh:

$("#asos").attr("src", "/ImageServlet?="+((new Date()).getTime()) )

This call to another method to get text value gives me old stuff:

        $.ajax({
        url:"checkCaptcha",
        type:"GET",
        cache: false,
        success: function( data) {
            alert(data);
        }
    });

Any feedback will be appreciated.

ps: here's the meat of the method getting the call:

        PrintWriter out = response.getWriter();
    response.setContentType("text/html");
    response.setDateHeader("Expires", 0 );

    // Set standard HTTP/1.1 no-cache headers.
    response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");


    // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");

    // Set standard HTTP/1.0 no-cache header.
    response.setHeader("Pragma", "no-cache");

    out.print( request.getSession( ).getAttribute("randomPixValue") );
    out.close();

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about servlets