zoukankan      html  css  js  c++  java
  • Jquery读取XML文件

    需要在服务器访问,以http://开头的

    XML文件

    <?xml version="1.0" encoding="utf-8" ?>
    <root>
      <keyWords>
        <details>新闻|毛毛</details>
     </keyWords>
    </root>

    Jquery获得信息

    $.ajax({
            url: "/js/keyWords.xml",
            dataType: "xml",
            type: "get",
            success: function (xml) {
                alert($(xml).find("keyWords").text().trim());       
         } });

    说明几点问题:

    1、如果用Post进行Ajax提交,可能会遇到405错误,提示没有权限访问,貌似是跨域,在本地测试的时候,没有认真去测试分析了,不知道跟Host文件有关系没?

    $(function(){
        $.ajax({url:"city1.xml",type:"post",dataType:"xml",success:function(msg){
                $(msg).find("Root>Item[pid='0']").each(function(){
                    $("<option></option>").text($(this).attr("value")).val($(this).attr("id")).appendTo($("#sheng"));
                });
                $("#sheng").change(function(){
                    var id=$(this).val();
                    $("#shi").empty();
                    $(msg).find("Root>Item[pid='"+id+"']").each(function(){
                        $("<option></option>").text($(this).attr("value")).val($(this).attr("id")).appendTo($("#shi"));
                    });
                    $("#shi").change();
                });
                $("#shi").change(function(){
                    var id=$(this).val();
                    $("#xian").empty();
                    $(msg).find("Root>Item[pid='"+id+"']").each(function(){
                        $("<option></option>").text($(this).attr("value")).val($(this).attr("id")).appendTo($("#xian"));
                    });
                });
                $("#sheng").change();
                $("#shi").change();
            }
        });
  • 相关阅读:
    Hibernate 基本写法
    JavaWeb中的中文乱码问题
    AJAXJson
    Hibernate 的几个概念
    sql 中的备份集、备份设备、媒体、媒体集
    收缩数据库日志文件
    AJAXjs
    rand一定要加srand随机数种子
    CheckBit,SetBit设置二进制位的方法使用
    memset(buf,0,100)和memset(buf,'\0',100)有什么区别?
  • 原文地址:https://www.cnblogs.com/jasonlny/p/3272737.html
Copyright © 2011-2022 走看看