2012-08-11 5 views
1

내가 jQuery의 아약스를 사용하여 파이썬 스크립트에서 XML 데이터를 반환하기 위해 노력하고있어에서 XML을 반환 할 때 :parseerror mod_python을

<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 반환 한 빨리 아무것도 경고 쇼 Success!을하지만, 내가 얻는 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! 

답변

2

으로 XML이 유효하지 않습니다, 당신은 루트 노드를 누락 (단일 루트 노드) 예 :

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

그래서 .. 나는 다른 방향을 찾고있었습니다 :) – Qiau

관련 문제