parse xml using jQuery
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 m开发者_高级运维y 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
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.
Why not simply use:
$.ajax({
type: "GET",
url: "webProject/webcontent/WEB-INF/config/ampliflex.xml",
dataType: "xml",
success: function(xml) {
}
});
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.
精彩评论