parseerror in jQuery when returning xml from mod_python
-
25-06-2021 - |
Frage
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!
Lösung
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>')
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow