Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what is the problem in the below code. i'm trying to load a part of xml file in a webpage(HTML) and I tried below synax but it doesn't work. If there is better way tell me.


JavaScript
$.ajax({
    type: "GET",
    url: "http://www.xmlfiles.com/examples/note.xml",
    dataType: "xml",
    success: function(xml){
        $(xml).find('note').each(function(){
            var to = $(this).find('to').text();
            console.log(to);
        });
    },

    error: function() {
        alert("An error occurred while processing XML file.");
    }
});
Posted
Comments
Ehsan Sajjad 5-Nov-15 6:05am    
any errors on console. what do you mean by not working, only saying not working does not helps to understand what could be wrong.
Gyaneswar kumar 5-Nov-15 6:34am    
replace text(); by value or innerxml etc..
ZurdoDev 5-Nov-15 7:46am    
1. Debug your code and see what is happening. Telling us that it doesn't work doesn't tell us anything.
2. See, http://stackoverflow.com/questions/16417211/load-xml-file-content-into-div-using-jquery. You may want to call parseXML first.
Anil Sharma1983 6-Nov-15 7:20am    
may be problem : Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.xmlfiles.com/examples/note.xml. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

You need to configure your Server to accept those calls

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900