我想在我的phonegap应用程序中解析xml webservice,但我不知道它是如何可能的。我试着用本地xml文件存储在远程服务器中,工作正常,但当我调用服务器端XML文件,然后我没有得到任何结果。请任何人有想法,然后请解决我的问题。请任何人有工作简单的代码,然后请发送给我。我试图从谷歌找出我的解决方案,但没有得到任何答案。请解决我的问题。我的服务器文件是http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml。在phonegap应用程序中解析xml的问题
4
A
回答
2
请尝试以下您的index.html文件的代码,我已经测试过的网址( http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml)在iPhone/Android模拟器和它的工作如魅力。
<html>
<head>
<script src="js/jquery-1.4.2.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script>
function bodyload(){
alert("We are calling jquery's ajax function and on success callback xml parsing are done");
$.ajax({
url:'http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml',
dataType:'application/xml',
timeout:10000,
type:'POST',
success:function(data) {
$("#bookInFo").html("");
$("#bookInFo").append("<hr>");
$(data).find("Book").each(function() {
$("#bookInFo").append("<br> Name: " + $(this).find("name").text());
$("#bookInFo").append("<br> Address: " + $(this).find("address").text());
$("#bookInFo").append("<br> Country: " + $(this).find("country").text());
$("#bookInFo").append("<br><hr>");
});
},
error:function(XMLHttpRequest,textStatus, errorThrown) {
alert("Error status :"+textStatus);
alert("Error type :"+errorThrown);
alert("Error message :"+XMLHttpRequest.responseXML);
$("#bookInFo").append(XMLHttpRequest.responseXML);
}
});
}
</script>
</head>
<body onload="bodyload()">
<button onclick="bodyload()">Ajax call</button>
<p id="bookInFo"></p>
</body>
</html>
输出 -
0
使用此:
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.css" />
<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a2/jquery.mobile-1.0a2.min.js"></script>
<script type="text/javascript">
$(function() {
$("#requestXML").click(function() {
$.ajax({
type: "POST",
url: "http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml",
data: "{}",
cache: false,
dataType: "xml",
success: onSuccess
});
});
$("#resultLog").ajaxError(function(event, request, settings, exception) {
$("#resultLog").html("Error Calling: " + settings.url + "<br />HTTP Code: " + request.status);
});
function onSuccess(data)
{
$("#resultLog").append(""+data);
$(data).find("Book").each(function() {
$("#resultLog").append("<br> Name: " + $(this).attr("name"));
$("#resultLog").append("<br> Address: " + $(this).attr("address"));
$("#resultLog").append("<br> Country: " + $(this).attr("country"));
$("#resultLog").append("<br><hr>");
});
}
});
</script>
按钮来调用上述方法:
<input id="requestXML" type="button" value="Request XML" />
+0
爵士,不工作请看到我的错误http://www.mediafire.com/?2ko925z4smk59u1我没有得到任何输出,请帮助我 – Sandeep
+0
上面的回答有更新,添加js和css导入到你的html。我更喜欢在模拟器或设备上运行它。 –
相关问题
- 1. 解析XML与iPhone应用程序的问题
- 2. 问题与iPhone应用程序解析XML的YouTube
- 3. 用于PhoneGap应用程序的JavaScript解析JSON解析器
- 4. PhoneGap的应用程序关闭问题
- 5. PhoneGap XML解析器?
- 6. JSON解析在iPhone应用程序中的问题
- 7. json在android应用程序解析中的问题
- 8. XML解析问题
- 9. XML解析问题
- 10. XML解析问题
- 11. 问题解析XML
- 12. XML解析问题
- 13. 解析XML问题
- 14. XML解析问题
- 15. XML解析问题
- 16. xml解析问题
- 17. XML解析问题
- 18. 解析问题在解析XML响应的Android
- 19. 用LINQ解析XML问题
- 20. Phonegap应用程序开始问题
- 21. PhoneGap问题返回到应用程序
- 22. 在android中的XML解析问题
- 23. 在php中解析xml的问题
- 24. 在Java中解析XML的问题
- 25. 在黑莓中解析xml的问题
- 26. 在Javascript中解析XML的问题
- 27. Android - XML解析器应用程序
- 28. 将XML解析为Android应用程序
- 29. Android应用程序XML解析错误
- 30. Python的XML解析问题
1件重要的事情,请将jquery文件的插件名称更改为您的结尾处的一个。 –
你好,这些脚本文件不可用。你会PLZ下载jquery.js,然后插入到您的HTML页面。 –
我得到了“NO TRANSPORT”错误。 http://www.jaysonragasa.net/files/test/resp.xml –