0

i am parsing Xml using ajax function in jquery in a jsp file

$.ajax({
        type: "GET",
        url: "sites.xml",
        dataType: "xml",
        success: function(xml) {

    }
});

My problem is my xml file is not in the same path as my jsp file. The jsp path is webProject/webcontent/temlates/store/SearchResult.jsp and the xml path is webProject/webcontent/WEB-INF/config/ampliflex.xml.

What should my url be in the $.ajax({ function?

Please Suggest

7
  • 1
    Use the absolute path to the file... Commented Jun 15, 2011 at 10:18
  • try this- ././WEB-INF/config/ampliflex.xml Commented Jun 15, 2011 at 10:22
  • Felix Kling :i am using it as url:"webProject/webcontent/WEB-INF/config/ampliflex.xml" but i am getting this error "Get localhost:7001/webProject/WebContent/WEB-INF/config/… 404 Not Found" i used firebug to c the problem Commented Jun 15, 2011 at 10:23
  • @romi- have you tried my option Commented Jun 15, 2011 at 10:24
  • @Vivek: this is also not working, stiil showing the same error . Commented Jun 15, 2011 at 10:25

3 Answers 3

1

I would have thought that the WEB-INF directory would be private by default and so not accessible via an AJAX request. Try moving the XML file to some other part of your project.

Sign up to request clarification or add additional context in comments.

4 Comments

yes when i use some other xml file of some other path this is working. But the problem is i can not move ampliflex.xml from WEB-INF. is there any other way that i can parse it here.
@Romi I would think that you don't want to make the whole WEB-INF directory publicly visible. The file will be visible to servlets running on the server, so if you really can't move the file then you could create a servlet that loads the file and passes it on.
@ alnorth29: I tried this too. But can i use this servlet with in javascript tag ???
@Romi It should work fine, just do the AJAX request to the URL in the usual way. You'll want to set the response type for the servlet to text/xml or application/xml.
0

Why not simply use:

$.ajax({
        type: "GET",
        url: "webProject/webcontent/WEB-INF/config/ampliflex.xml",
        dataType: "xml",
        success: function(xml) {

    }
});

1 Comment

@Romi do as other have suggested and move the xml then use the path as i've shown
0

Do you see the file if you try accessing it directly with your browser (via localhost i mean)? if your ajax request can see the file so can your browser directly. i would suggest trying to find the correct url in your browser and use that in your ajax request.

Furthermore as mentionned above it is possible the WEB-INF directory is not accessible to client (hence my first question in this comment) so you can also try moving the xml file to a directory you know is accessible.

1 Comment

kyushiro: I used a xml file which is not accessible via browser but it is still parsable via ajax .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.