Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert XML to JSON in an external reference #29

Closed
Realybig opened this issue Apr 9, 2017 · 3 comments
Closed

How to convert XML to JSON in an external reference #29

Realybig opened this issue Apr 9, 2017 · 3 comments

Comments

@Realybig
Copy link

Realybig commented Apr 9, 2017

why doesn't working this code?

test.xml

<xml><a>It Works!</a></xml>

html code

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="js/xmltojson.js"></script>
</head>

<body>
    <script>
        $.ajax({
            url:'test.xml',
            type:'GET',
            datatype:'xml',
            success:function(data){
                console.log(data)
                testString = data;
                result = xmlToJSON.parseString(testString); // parse
                console.log(result)
            },
            error:function(){
                console.log('error')
            }
        })
        
    </script>
</body>

</html>
@ghost
Copy link

ghost commented Apr 9, 2017 via email

@Realybig
Copy link
Author

Error in the picture below
123123

@ghost
Copy link

ghost commented Jul 11, 2017

The parseString functions expects a string. It looks as though you are passing an xml object (set by your jQuery datatype. Try using xmlToJSON.parseXML(testString) instead.

Let me know if that works for you.

@ghost ghost closed this as completed Aug 27, 2017
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant