3

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

1

2 Answers 2

6

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

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

Sign up to request clarification or add additional context in comments.

Comments

0

your input xml is not proper,

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

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.