gpt4 book ai didi

jquery - 从 mod_python 返回 xml 时 jQuery 中出现解析错误

转载 作者:行者123 更新时间:2023-12-01 05:57:10 25 4
gpt4 key购买 nike

我正在尝试使用 jQuery 的 .ajax 从 Python 脚本返回 XML 数据:

<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>

当我的script.py没有返回任何内容时,警报显示成功!,但是当我尝试添加一些XML数据时,我得到的只是parseerror。我应该如何返回 XML 而不会出现解析错误?

script.py - 工作

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

script.py - 损坏

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

最佳答案

您的 xml 无效,您缺少根节点(单个根节点),例如

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

关于jquery - 从 mod_python 返回 xml 时 jQuery 中出现解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11917955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com