C#の:上限に達した場合には普遍的な形+ AJAXサイトは、読むために記事の数を制限達成、あなたは記事(単品)を支払う必要があります

フィールドに示すように、サイトの背景には、普遍的なフォームを作成し
ここに画像を挿入説明
、ユーザーが成功したか失敗した後、AJAXの非同期サービス処理を渡すパラメータ、htmlページにログインしているかどうかを判断します。

//判断用户是否登陆
<script type="text/javascript">
	<%csharp%> 
	DTcms.Model.users muc=GetUserInfo(); 
	if(muc==null) {
	<%/csharp%>
	$('#centent').html('<div></div>');
layer.confirm('请先登陆,再继续阅读文章!', {
    btn: ['确定'] //按钮
   }, function(){
        location.href = '/login.aspx'; 
});
<%csharp%>
}else 
	{	
<%/csharp%>
//参数传递 ajax异步
var userid=<%=muc.id%>;
var wzid=<%=model.id%>;
var title="<%=model.title%>";
$.ajax({
		url: '/dev/ClickLoad.ashx',
type: 'POST',
dataType: 'json',
data: {
	action: 'GetContent',
	userid:userid ,
	wzid: wzid,
	title:title,
},
//成功或失败后的业务处理
success: function(d) {
if(d.code==0){
	$('#centent').html(d.content);
}else{
	$('#centent').html('<div></div>');
	 layer.msg(d.msg, function(){
    $('#centent').html('<div class="goumai"><a href="/zhifu.aspx?actionss={chanid}&wzid={model.id}">点击购买</a></div>');          
   });
}
},
error: function(e) {}
})
<%csharp%> 
	}
<%/csharp%>
    	
    </script>

C#のASHXのビジネスロジック

<%@ WebHandler Language="C#" Class="DTcms.Web.dev.ClickLoad" %>
using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using DTcms.Common;
using DTcms.DBUtility;
using NetWing.Common.Data.SQLServer;
using NetWing.Common.Request;
using NetWing.Common;
namespace DTcms.Web.dev
{
    /// <summary>
    /// dev 的摘要说明
    /// </summary>
    public class ClickLoad : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request["action"];
            if (string.IsNullOrEmpty(action))
            {
                context.Response.Write("{\"code\":1000, \"msg\":\"请求失败,参数有误!\"}");
                return;
            }
            switch (action)
            {

                case "GetContent":  //获得要购买的文章
                    GetContent(context);
                    break;


            }
        }
        #region  购买文章
        public void GetContent(HttpContext context)
        {
            string userid = context.Request["userid"];
            string wzid = context.Request["wzid"];
            string title = context.Request["title"];

            if (string.IsNullOrEmpty(userid) || string.IsNullOrEmpty(wzid))
            {
                context.Response.Write("{\"code\":1000, \"msg\":\"请求失败,参数有误!\"}");
                return;
            }
            string dtA = (string)SqlEasy.ExecuteScalar("select content from dt_article where id=" + wzid);
            DataRow drw = SqlEasy.ExecuteDataRow("select * from nw_customform_user_ffwz where userid=" + userid + " and wzid=" + wzid);

            string cishusql = "select * FROM dt_article_attribute_value where article_id="+wzid+"";//查询后台填写的文章可免费查看次数
            DataRow tongji = SqlEasy.ExecuteDataRow(cishusql);
            int lick = int.Parse(tongji["cishu"].ToString());
          
         
            if (drw == null)
            {
                int code = SqlEasy.ExecuteNonQuery("INSERT INTO nw_customform_user_ffwz (userid,wzid,statu,add_time,number,title) VALUES (" + userid + "," + wzid + ",0,'" + DateTime.Now + "',1,'" + title + "')");
                if (code > 0)
                {
                    context.Response.Write("{\"code\":0, \"msg\":\"请求成功!\",\"content\":\"" + dtA + "\"}");
                }
                else
                {
                    context.Response.Write("{\"code\":200, \"msg\":\"网络繁忙,请重新刷新网页!\",\"content\":\"" + dtA + "\"}");
                }
            }
            else
            {
                if (int.Parse(drw["statu"].ToString()) == 0 && int.Parse(drw["number"].ToString()) < lick)
                {
                    int number = int.Parse(drw["number"].ToString()) + 1;
                    int code = SqlEasy.ExecuteNonQuery("update nw_customform_user_ffwz set number=" + number + " where id=" + drw["id"].ToString());
                    if (code > 0)
                    {
                        context.Response.Write("{\"code\":0, \"msg\":\"请求成功!\",\"content\":\"" + dtA + "\"}");
                    }
                    else
                    {
                        context.Response.Write("{\"code\":200, \"msg\":\"网络繁忙,请重新刷新网页!\",\"content\":\"" + dtA + "\"}");
                    }
                }
                else if (int.Parse(drw["statu"].ToString()) == 1)
                {
                    int number = int.Parse(drw["number"].ToString()) + 1;
                    int code = SqlEasy.ExecuteNonQuery("update nw_customform_user_ffwz set number=" + number  + " where id=" + drw["id"].ToString());
                    if (code > 0)
                    {
                        context.Response.Write("{\"code\":0, \"msg\":\"请求成功!\",\"content\":\"" + dtA + "\"}");
                    }
                    else
                    {
                        context.Response.Write("{\"code\":200, \"msg\":\"网络繁忙,请重新刷新网页!\",\"content\":\"" + dtA + "\"}");
                    }
                }
                else
                {
                    context.Response.Write("{\"code\":200, \"msg\":\"购买后才能查看!\"}");
                }
            }
        
        }
        #endregion


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
リリース6元記事 ウォンの賞賛3 ビュー165

おすすめ

転載: blog.csdn.net/weixin_43739179/article/details/102838151
おすすめ