2014年3月3日 星期一

Jquery 讀取 xml

     
xml
       <info>
<user>
<name>王小虎</name>
<sex>男</sex>
<habit>电脑游戏</habit>
</user>
<user>
<name>张小凡</name>
<sex>男</sex>
<habit>体育游戏</habit>
</user>
<user>
<name>卓不凡</name>
<sex>男</sex>
<habit>网球游戏</habit>
</user>
</info>


.ashx 檔案
       string xml = "";
     
        string str = "";
        StreamReader file = new StreamReader(context.Server.MapPath("~/xml.txt"));   //讀取xml字串
        while ((str = file.ReadLine()) != null)
        {
            xml += str;
        }

        file.Close();
     
        context.Response.ContentType = "text/xml";
        context.Response.Write(xml);

  .aspx檔案
           var ajaxUrl = 'xmlRead.ashx';
            $.ajax({
                async: false,
                type: 'POST',
                url: ajaxUrl,
                dataType: 'xml',   //回船型態必須以xml
                success: function (xml) {    /*執行成功後接收回傳值*/


                    $(xml).find("info").children("user").each(function (i) {
                        var name_value = $(this).children("name").text();
                        var sex_value = $(this).children("value").text();

                        alert("姓名:" + name_value + "  性别:" + sex_value);
                    });


                }
            });

標籤: ,

2014年1月16日 星期四

Jquery Mobile 捲軸到底 並執行

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script>

<script type="text/javascript">

    $(function () {
        $(document).on("scrollstart", function () {

            if ($(window).scrollTop() + $(window).height() == $(document).height()) {
                //捲軸到底後會執行
                $("#content").clone().appendTo($("#content"));

            }
        });

    });
</script>

<body>
    <div id="terms" style='overflow:auto;'>
        <div data-role="page">
            <div data-role="header">
                <h1>silentScroll() example</h1>
            </div>
            <div id="content" role="main" class="ui-content">
                <a href="#" onclick="" data-role="button">Go down 100 pixels</a>
                <p> <br><br>Here, we have some text so that we can have <br>
                some vertical space in order to demonstrate <br>
                the silentScroll() method.<br><br></p>
                <a href="#" onclick="$.mobile.silentScroll(0)" data-role="button">Back to Top</a>
            </div>
            <div data-role="footer">
                <h4> </h4>
            </div>
        </div>
    </div>
   
</body>

標籤: ,