1

I'm trying to return XML-data from a Python script using jQuery's .ajax:

<html><head>
  <script type="text/javascript" src="jquery-1.7.2.js"></script>
  <script type="text/javascript">
    $(document).ready(function() {
      $.ajax({
        type: "POST",
        url: "script.py/method",
        dataType: "xml",
        success: function(xml) { alert('Success!'); },
        error: function(request, error) { alert(error); }
      });
    });
   </script>
 </head><body></body></html>

When my script.py returns nothing the alert show Success!, but as soon as I try to add some XML data all I get is parseerror. How should I do to return XML without getting a parseerror?

script.py - working

def method(req):
    req.content_type = 'text/xml'
    req.write('')  # Works!

script.py - broken

def method(req):
    req.content_type = 'text/xml'
    req.write('<item>1</item><item>2</item>') # parserror!

1 Answer 1

2

Your xml isn't valid, you are missing a root node(a single root node), eg

def method(req):
    req.content_type = 'text/xml'
    req.write('<items><item>1</item><item>2</item></items>')
Sign up to request clarification or add additional context in comments.

1 Comment

So obvious.. I was looking another direction :)

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.