unable to load xml from external file using jQuery

前端 未结 2 835
一整个雨季
一整个雨季 2020-11-30 15:49

I\'m trying to load external xml using the following code but it is not working

$( document ).load( \"data.xml\", function(  response, status, xhr ) {               


        
相关标签:
2条回答
  • 2020-11-30 16:17

    Maybe this is what you are looking for....

    $(document).ready(function(){
        $.ajax({
            url: 'data.xml',
            dataType: 'xml',
            success: function(response, status, xhr){
               console.log( xhr.status + " " + xhr.statusText );
            }
         });
    });
    

    UPDATE

    Read this post

    0 讨论(0)
  • 2020-11-30 16:38

    After a long struggle and with the help of community I figured out the issue.

    The same-origin policy restricts how a document or script loaded from one origin can interact with a resource from another origin.

    Means this is not possible with the system file, so with the help of this answer, I used WAMPServer to run my script and it worked like a charm.

     $.get("http://localhost/public_html(1)/public_html/xml/data.xml",
                                         function(  response, status, xhr ) {        
            console.log( response );
        });
    

    Thank you!

    0 讨论(0)
提交回复
热议问题