Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery parse error on xml document

Tags:

jquery

ajax

xml

I am making an ajax request for an xml file but getting a parse error because of the xml declaration.

AJAX request:

    <script>
        $(document).ready(function(){
            $.ajax({
                url: "/test/test.xml",
                dataType: "xml",
                password: "*******",
                username: "[email protected]",                   
                success:function( result){
                    console.log(result);
                },
                error: function(xhr, status, error){
                    console.log(error);
                    console.log(status);
                }
            });
        });
    </script>

Response:

<?xml version="1.0" encoding="UTF-8"?>
<token>
  <guid>c93f12c71bec27843c1d84b3bdd547f3</guid>
  <id type="integer">1</id>
</token>

I get a parse error on the first line of the xml. In prod I'll be requesting an xml file that looks just like this . I tried a test and removed the xml declaration and it worked fine but I will not have control over the xml declaration in the real environment.

Any help would be greatly appreciated

like image 697
DroidCommander Avatar asked Sep 01 '26 15:09

DroidCommander


1 Answers

There should be a space between encoding="UTF-8" and ?>. Like encoding="UTF-8" ?>.

See: http://xmlwriter.net/xml_guide/xml_declaration.shtml

like image 132
Yes Barry Avatar answered Sep 04 '26 10:09

Yes Barry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!