我尝试使用jQuery Ajax发布XML请求并获取XML响应。 我必须点击以下URL来发布请求并获取XML响应。
请求
var xml_response=http://test.test.in:8080/RestAPI/ServiceRequestServlet?request=<xml><request><functiontype>2003</functiontype><groupzid>185</groupzid><moduleid>8</moduleid><servicetype>21</servicetype></request></xml>
回复
<xml>
<response>
<servicetype>21</servicetype>
<functiontype>2003</functiontype>
<statuscode>0</statuscode>
<statusmessage>Success</statusmessage>
<groupzid>185</groupzid>
<servicerequestcategories>
<element>
<category>dtdc courier</category>
</element>
<element>
<category>gardening</category>
</element>
<element>
<category>plumber</category>
</element>
<element>
<category>Electrician</category>
</element>
<element>
<category>Others</category>
</element>
</servicerequestcategories>
</response>
</xml>
jQuery的:
$(document).ready(function(){
$("#dvContent").append("<ul></ul>");
$.ajax({
type: "POST",
url: xml_response,
dataType: "xml",
success: function(xml){
$(xml).find('Response').each(function(){
var sr_category = $(this).find('servicerequestcategories').text();
var category = $(this).find('category').text();
});
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
});
当我尝试给出这个时,我没有得到回复,而且它说XML过程错误。