开发者

ajax call to servlet puzzler

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").a开发者_C百科ttr("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();


Let the servlet send the following headers:

response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Pragma", "no-cache");


As per the comments on the question, here's a copy of the comment which needs to be reposted as an answer:

Are you using a 3rd party captcha API or a homegrown one? If 3rd party, which one? Are you also sure that they all uses the same session? Debug/print session.getId() in both the image and captcha servlets. Are you sure that the captcha servlet got called? Debug the doGet() method.


Looks like you need to add a file extension to your url. Assuming it's an html page you're making the ajax call to:

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


... progress report:

- session id:

Both methods getting called on the server print the same si FireBug also shows the same si on initial page load and subsequent page reloads They both print the same captcha textual value.

... here's something interesting. When I reload only the image through ajax call, the image gets reloaded, but the method does not print to console.

Method that is supposed to get the text value does print to console the old value

So, image gets reloaded but nothing prints to console and text value get printed but it's old.

When looking at the ajax call in FireBug, what am I looking for exactly? (That's my weakest spot I'm afraid)

... hm ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜