日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ajxa异步请求数据

發布時間:2025/3/20 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ajxa异步请求数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

方法一:同時處理多個返回值

ListData.cs 類


using System;

using System.Collections.Generic;

using System.Web;

using System.Text;

public class ListData

{

? ? private int pageSize;

? ? public int PageSize

? ? {

? ? ? ? get { return pageSize; }

? ? ? ? set { pageSize = value; }

? ? }


? ? private int records;

? ? public int Records

? ? {

? ? ? ? get { return records; }

? ? ? ? set { records = value; }

? ? }

? ? public ListData()

? ? {

? ? }

? ? public ListData(int pageSize, int records)

? ? {

? ? ? ? this.PageSize = pageSize;

? ? ? ? this.Records = records;

? ? }


? ? public string ToJson()

? ? { ? ? ? ?

? ? ? ? System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

? ? ? ? return serializer.Serialize(this);

? ? }

}


一般處理程序ashx:


? ListData ldata = new ListData();實例化類

? ldata.PageSize = pageSize;//每頁顯示多少條記錄

? ldata.Records = recount;//總記錄數


?context.Response.Write(ldata.ToJson());//輸出到頁面


頁面接收值:


? ? $(function () {

var title = $("#Info_title").text(); //評論主題

? ? ? ? var url = '<wtl:system type="Systempath"></wtl:system>sitecn/conmmentOn/ConmmentOnListPage.ashx';//鏈接地址:一般處理程序地址

? ? ? ? var date = { ctent: "0", pageTopic: "page_indexs",title:title };

? ? ? ? $.post(url, date, function (getdata) {

? ? ? ? ? ? var tip = eval("(" + getdata + ")");

? ? ? ? ? ? ? ? ? ? $("#page_count").html("" + tip.Records + "");//總條數

? ? ? ? $("#page_Size").html("" + tip.PageSize + ""); //每頁顯示幾條

? ? ? ? });

? ? });



方法二:處理單個值的處理


前端:

<script type="text/javascript">

? ? function GetPrice(p) {

? ? ? ? $(function () {

? ? ? ? ? ? var url = '{$syspath}Ajax/handler.ashx';

? ? ? ? ? ? var date = { price: p };

? ? ? ? ? ? $.post(url, date, function (getdata) {

? ? ? ? ? ? ? ? if (getdata > 0) {

? ? ? ? ? ? ? ? ? ? $("#discount_onclick").hide();//隱藏

? ? ? ? ? ? ? ? ? ? $("#discount_price").text(getdata);//得到值

? ? ? ? ? ? ? ? }


? ? ? ? ? ? });

? ? ? ? });


? ? }



? ? $(function () {

? ? ? ? var url = '{$syspath}Ajax/Discount.ashx';

? ? ? ? var date = { state: "0" };

? ? ? ? $.post(url, date, function (getdata) {

? ? ? ? ? ? $("#id_discount").text(getdata);//得到值

? ? ? ? });


? ? });


</script>




一般處理程序:

<%@ WebHandler Language="C#" Class="Discount" %>


using System;

using System.Web;

using System.Data;


public class Discount : IHttpHandler {

? ??

? ? public void ProcessRequest (HttpContext context) {

? ? ? ? context.Response.ContentType = "text/plain";

? ? ? ? try

? ? ? ? {

? ? ? ? ? ? string result = string.Empty;

? ? ? ? ? ? //string option1 = string.Empty;


? ? ? ? ? ? DataTable dt = (Whir.Repository.DbHelper.CurrentDb.Query("select top 1 * from dbo.Whir_Mem_Member where loginName=@0 and isdel=0",new FrontBasePage().GetUserName())).Tables[0];

? ? ? ? ? ? if (dt != null && dt.Rows.Count > 0)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? foreach (DataRow dr in dt.Rows)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? if (!string.IsNullOrEmpty(dr["discount"].ToString()))

? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? result = dr["discount"].ToString();

? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? context.Response.Write(result);

? ? ? ? }

? ? ? ? catch (Exception ex) { }

? ? }

?

? ? public bool IsReusable {

? ? ? ? get {

? ? ? ? ? ? return false;

? ? ? ? }

? ? }


}

本文轉自程序猿博客51CTO博客,原文鏈接http://blog.51cto.com/haihuiwei/1606738如需轉載請自行聯系原作者


365850153

總結

以上是生活随笔為你收集整理的ajxa异步请求数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。