简体   繁体   中英

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 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM