最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery使用$.ajax進(jìn)行異步刷新的方法(附demo下載)

 更新時間:2015年12月04日 11:33:33   作者:游響云停  
這篇文章主要介紹了jQuery使用$.ajax進(jìn)行異步刷新的方法,涉及jQuery實現(xiàn)ajax異步刷新實現(xiàn)數(shù)據(jù)交互的相關(guān)技巧,并提供了完整示例demo供讀者下載參考,需要的朋友可以參考下

本文實例講述了jQuery使用$.ajax進(jìn)行異步刷新的方法。分享給大家供大家參考,具體如下:

最近要用到j(luò)query進(jìn)行異步讀取數(shù)據(jù)的功能,jquery提供了許多內(nèi)置的異步讀取函數(shù),給大家演示下最常用的$.ajax用法

在客戶端文本框輸入一個內(nèi)容,然后在服務(wù)器端返回時間

在DEMO中要用到ashx文件,用于獲取服務(wù)器的信息

效果圖片

escape() 函數(shù)可對字符串進(jìn)行編碼,這樣就可以在所有的計算機(jī)上讀取該字符串。

客戶端代碼

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<mce:script type="text/javascript" src="js/jquery-1.4.2.min.js" mce_src="js/jquery-1.4.2.min.js"></mce:script> 
 <title></title> 
 <mce:script type="text/javascript"><!-- 
  function GetData() { 
   if ($('#Text1').val() == '') { 
    alert('請輸入內(nèi)容!'); 
    return; 
   } 
   $.ajax({ 
    type: "GET", 
    url: "ContentHandler.ashx?name=" + $('#Text1').val(), 
    cache: false, 
    data: { sex: "男" }, 
    success: function(output) { 
     if (output == "" || output == undefined) { 
      alert('返回值為空!'); 
     } 
     else { 
      output = eval("(" + output + ")"); 
      $('#divmsg').html("姓名:" + output.name + "----" + "日期:" + output.dt); 
     } 
    }, 
    error: function(XMLHttpRequest, textStatus, errorThrown) { 
     alert("獲取數(shù)據(jù)異常"); 
    } 
   }); 
  } 
// --></mce:script> 
</head> 
<body> 
 <form id="form1" runat="server"> 
 <div> 
  ajax使用demo 
 </div> 
 <div> 
<input id="Text1" 
   type="text" /> 
     <input id="Button1" type="button" value="獲取數(shù)據(jù)" onclick="GetData()"/> 
   </div> 
  <div id='divmsg'> 
  </div> 
 </form> 
</body> 
</html>

服務(wù)器端代碼

<%@ WebHandler Language="C#" Class="ContentHandler" %> 
using System; 
using System.Web; 
public class ContentHandler : IHttpHandler { 
 public void ProcessRequest (HttpContext context) { 
  string output = ""; 
  string name = context.Request.Params["name"]; 
  output = GetJsonData(name); 
  context.Response.ContentType = "text/plain"; 
  context.Response.Write(output); 
 } 
 public bool IsReusable { 
  get { 
   return false; 
  } 
 } 
 public string GetJsonData(string aa) 
 { 
  string result = "{name:/""+aa+"/",dt:/""+DateTime.Now.ToString()+"/"}"; 
  return result; 
 } 
}

完整實例代碼點擊此處本站下載

希望本文所述對大家jQuery程序設(shè)計有所幫助。

相關(guān)文章

最新評論

南平市| 星子县| 罗田县| 中卫市| 赤壁市| 张北县| 巴林左旗| 彩票| 邵阳市| 广德县| 壶关县| 开远市| 乐至县| 扎鲁特旗| 东乡县| 拜城县| 罗定市| 循化| 闻喜县| 雅江县| 上杭县| 应城市| 临沂市| 彭山县| 平顺县| 曲沃县| 内江市| 浑源县| 维西| 乾安县| 舒城县| 法库县| 涞源县| 江山市| 德化县| 仙桃市| 呼和浩特市| 崇信县| 双鸭山市| 南部县| 牙克石市|