今天遇到的jquery $.ajax()取xml数据的小问题
2010-11-20 15:59
627 查看
今天想做一个用$.ajax()从xml中读取数据的这么一个异步交互过程
开始的代码如下:
我恍然大悟,原来这种直接用pretendTo插入的方法会连tagname也插入进去,难怪chrome和Safari不能识别(从另一个方面来说
Firefox原来强大这么多……)
于是修改后的代码如下:
先取出所需元素的text()的值,再以修改html的方法html()插入容器中,大功告成啦!测试均通过[/code]
开始的代码如下:
").find("auther").appendTo($("#contain"))]
也就是,从App_all.xml这个文件中找到id为“id-1”的这一项,并将继续在其子节点中找到auther标签,并将其内容加入到id 为contain
的div中,xml中我要查找的内容为<auther>cocept</auther>,我就是想把cocept这个字段取出来,放入容器中
结果这段代码在firefox中生效,在opera中也生效,但是在Safari和chrome中却没有效果,于是我上jQuery的官方论坛,和StackFlowover
论坛提问,后者有人回复我:
I assure you I was using $.ajax with Chrome just five hours ago at the office, and had no such problem.
I also imagine they use it here on SO and I have no problems here. I have no problems on jQueryUI in Chrome. I think it is your code.
大意就是斩钉截铁的说他用起来没有问题,是我自己的问题,我也纳闷了,后面也有人给我的建议更复杂:
You should use chrome's or safari's built-in developer tools (ctrl+shift+i) to track JS errors and track actual AJAX requests.
Is your code wrapped in document.ready? Is there any erros in javascript console? Also try to output something after success callback line.
Another cause for this could be incorrect mime-type for your XML file returned by server. It should be [Content-type: text/xml].
You can check that in chrome's or safari's built-in developer tools - just look for headers tab when xml resource is selected.
If it 's actual problem, you may need to tweak web-server configuration (main config or .htaccess for apache) to return correct mime-type
毕竟是自学jquery ajax框架刚起步……就遇到这么棘手的问题,的确麻烦……
但是,由于我一个不经意的发现,问题迎刃而解……
我用firebug查看成功后的页面元素状态,发现:<div id="contain">
<auther>cocept</auther>
</div>
我恍然大悟,原来这种直接用pretendTo插入的方法会连tagname也插入进去,难怪chrome和Safari不能识别(从另一个方面来说
Firefox原来强大这么多……)
于是修改后的代码如下:
success: function (xml) { $("#contain").html($(xml).find("app[id='id-1']").find("auther").text()); }
先取出所需元素的text()的值,再以修改html的方法html()插入容器中,大功告成啦!测试均通过[/code]
相关文章推荐
- jquery $.ajax()取xml数据的小问题解决方法
- jquery $.ajax()取xml数据的小问题解决方法
- jquery $.ajax()取xml数据的小问题解决方法
- 今天遇到Oracle审计表AUD$数据过大问题
- 关于jquery中ajax数据返回类型问题
- 使用JQuery的Ajax操作html,xml,json数据
- jQuery解析AJAX返回的html数据时碰到的问题与解决
- S2SH+ajax+json-----jQuery中$.ajax解析xml、json格式数据
- jquery 请求ie缓存,数据不更新的问题【ajax禁用缓存解决ie数据不更新的问题】
- 把DataTable中的数据拼接成XML时遇到的问题
- jquery 请求ie缓存,数据不更新的问题【ajax禁用缓存解决ie数据不更新的问题】
- jquery动态增加表格表单行来插入数据-------遇到的兼容问题和radio问题
- jQuery的ajax()检验用户名;通过jQuery的load()/get()/post()方法实现;使用XMLHTTPRequest对象来进行AJAX的异步数据交互
- javaweb-react的入门遇到的问题三:ajax获取数据与循环处理放入列表
- jQuery发送ajax请求,IE有缓存,数据不更新问题
- 在jQuery中利用AJAX加载XML数据并解析
- jQuery中$.ajax解析xml、json格式数据
- jquery ajax里面的datetype设成json时,提交不了数据的问题
- 新学的插件jquery.tablesorter很好用,说说遇到的表格动态添加的数据不能排序的问题
- 类型:JQuery;问题:ajax调用ashx文件;结果:ashx文件怎么获取$.ajax()方法发送的json数据