-1

I have a xml url, need to bind the same xml(with out changing the xml format) to a div element using jquery ajax call. Please find my smaple code below

   <div class="json-full-output">
   <pre></pre>
   </div>



        $.ajax({
            type: "GET",
              url:APIUrl,
              dataType: "xml" ,
              success: function (xml) {
                var xmlDoc = $.parseXML(xml),
                     $xml = $(xmlDoc);
                $(".json-full-output pre").append($xml);
            },
         });
7
  • How about simply: $(".json-full-output pre").text(xml);? Commented Mar 26, 2018 at 6:34
  • what is the problem you are getting? Commented Mar 26, 2018 at 6:34
  • Nagarraju.. it is not binding any thing in UI Commented Mar 26, 2018 at 6:37
  • try this if you find solution... stackoverflow.com/questions/889688/… Commented Mar 26, 2018 at 6:38
  • acdcjunior .... if I used above code it is showing [object XMLDocument] in UI Commented Mar 26, 2018 at 6:39

1 Answer 1

0

To show the xml without changing it format. In ajax method change the data type from "xml" to "text", and in success method directly display the xml data without converting into xml object, and also use 'text' method to display the content instead of 'append'. Please try the below code.

                $.ajax({
                type: "GET",
                //url: "/ModelDesigner/GetFullXmlDataObjectForModel",
                url:APIUrl,
               // data: params,
                dataType: "text" ,
               // async: false,
                success: function (xml) {
                    console.log(xml);
                    /*var xmlDoc = $.parseXML(xml),
                         $xml = $(xmlDoc);
                        */ 
                    $(".json-full-output pre").text(xml);
                },
               //contentType: 'application/json'
            });
Sign up to request clarification or add additional context in comments.

1 Comment

thanks shanmugasuresh.P . It is binding now, but it is not showing in a xml format... all tags are merged and showing In a single file...

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.