AJAX not working with URL rewritten page

Splash Forums Rewrite Users AJAX not working with URL rewritten page

This topic contains 3 replies, has 3 voices, and was last updated by  Christian Kaltepoth 2 years, 9 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #25237

    rahulsoni
    Participant

    Hi all,

    I’m trying to call jQuery’s AJAX method in my jsp page(“abcd.jsp”) to load some content into a DIV on a Button click.

    I’ve a JSP (“new.jsp”), its URL is mapped to a Servlet(“myservlet.java”) using URL Rewrite.This servlet forwards the request to “abcd.jsp”. Now when the user clicks on the Button in “abcd,jsp”, the click() method gets called but the AJAX method doesn’t work.Both $.get(“myservlet”) & $.post(“myservlet”) fail.

    When I remove the URl Rewrite rule, then everything works fine..
    Also, when I run this “abcd.jsp” page directly, eveything works OK.Both these method works and displays content send by servlet..

    Does these AJAX get & post methods deal with the URL of the page ??
    or, Am I doing something wrong ??

    Thanks in advance.

    #25243

    Could you paste a dump of the network traffic when attempting to do your AJAX request? (Via your browser’s network traffic inspection tab) Thanks.

    https://developers.google.com/chrome-developer-tools/docs/network#network_panel_overview

    #25249

    rahulsoni
    Participant

    Hello Lincoln Sir,

    I have attahced the Network Traffic Shot picture with this comment.

    I searched on the internet and found that this is common problem of AJAX not working with URL rewrite.

    In case of Microsoft IIS people found the sol’n to be:

    “you can not create the url rewrite on the root directory and that you must have a directory between in order for ajax to continue working. ”

    Ex:
    url rewrite to: http://www.bandsUK.com/U2 will break all ajax
    url rewrite to: http://www.bandsUK.com/bands/U2 will keep ajax working.

    So does this apply to our rewrite too ???
    And if yes then how ???

    Thanks

    Attachments:
    1. New-Picture
    #25252

    The problem is that you are getting a 404 when sending the request to your server. So I guess the URL is not correct.

    Is /TechTalk/newjsp/newserv the correct URL? Please note that if you rewrite the URL of your JSP and then use relative URLs for the AJAX request you may run into problems.

    I recommend to use absolute URLs instead. So instead of:

    $.post(“myservlet”)

    You should use:

    $.post(“/TechTalk/myservlet”)

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

Comments are closed.