• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    初次體驗.NET Ajax無刷新技術

    發布: 2008-4-03 14:25 | 作者: haolaiwu | 來源: blog | 查看: 50次 | 進入軟件測試論壇討論

    領測軟件測試網 早就聽說Ajax技術了,傳說中是一種很牛的東西,號稱無刷新,其實是在web上通過javascript,使用異步的xmlhttp請求,實現無刷新的web界面?上б恢睕]有體驗過, 先后聽做PHP的朋友用過PHP的Ajax開發包,而且做了很多很酷的東西,使小生羨慕不已。 今天下了一個.net Ajax開發包,該開發包包括ASP2.0和目前ASP1.1版使用的Ajax,詳細地址參見http://ajax.schwarz-interactive.de/,接下來,開工。

      1. 新建一個項目,在引用中添加引用Ajax.dll,Ajax.dll位于下載的壓縮包里面。

      2.建立HttpHandler,在 web.config里面加上

      <configuration>
      <system.web>
      <httpHandlers>
      <add verb="POST,GET" path="ajax/*.ashx" type ="Ajax.PageHandlerFactory, Ajax" />
      </httpHandlers>
      ...
      <system.web>
      </configuration>

      3.新建一個類DemoMethods,這個類實現獲取客戶端MAC地址:

      using System;
      using System.Web;

      namespace AjaxSample
      {
      /// <summary>
      /// Summary description for Methods.
      /// </summary>
      public class DemoMethods
      {

      [Ajax.AjaxMethod]
      public string GetCustomerMac(string clientIP) //para IP is the client's IP
      {
      string mac = "";

      System.Diagnostics.Process process = new System.Diagnostics.Process();
      process.StartInfo.FileName = "nbtstat";
      process.StartInfo.Arguments = "-a "+clientIP;
      process.StartInfo.UseShellExecute = false;
      process.StartInfo.CreateNoWindow = true ;
      process.StartInfo.RedirectStandardOutput = true;

      process.Start();

      string output = process.StandardOutput.ReadToEnd();
      int length = output.IndexOf("MAC Address = ");

      if(length>0)
      {
      mac = output.Substring(length+14, 17);
      }

      process.WaitForExit();

      return mac.Replace("-", "").Trim();
      }
      }

      }

      4.寫javascript,新建一個名為default,js文件如下:

      function GetMac()
      {
      var clientIP="192.168.0.1";
      document.getElementById("Mac").value=DemoMethods.GetCustomerMac(clientIP).value
      alert(DemoMethods.GetCustomerMac(clientIP).value);
      }

      5.在某個Aspx頁面放上一個html 的button

      在頁面上<head>中引用default.js : <script language="javascript"   src="default.js"></script>

      在INPUT的onclick事件中加上onclick="javascript:GetMac()"

      <INPUT style="Z-INDEX: 101; LEFT: 392px; POSITION: absolute; TOP: 176px"   type="button"
      value="客戶端獲取IP" onclick="javascript:GetMac();">

      6.修改Global.asax的Application_Start事件,設置Ajax的HandlerPath :

      protected void Application_Start(Object sender, EventArgs e)
      {
      Ajax.Utility.HandlerPath = "ajax";
      }

      運行看看效果。是不是沒有刷新就在服務器端取到客戶端的MAC地址??

      需要注意的是:該版本的.net Ajax需要手工在中Global.asax加上Ajax.Utility.HandlerPath = "ajax"; 配置文件web.config必須加上HttpHandler的配置信息!

      該開發包的新版本還沒有來得及體驗,估計新版本中會方便一些,可能會去掉手動的設置Global.asax的Application_Start事件中加上Ajax.Utility.HandlerPath = "ajax";以及其他麻煩的設置!期待ing……

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/

    TAG: ajax AJAX Ajax


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>