可以使用一个自定义计算函数,在自定义计算函数中使用ajax调用后台服务,实现服务器端计算。

定义计算函数

定义一个自定义计算函数,并调用后台服务

// 调用服务端计算

function callservices(price, qty) {

   var rv;

YZSoft.Ajax.request({

       url: YZSoft.$url('Demo/Samples/Services.ashx'),

       async:false,

       params:{

           method:'Calc',

           price:price,

           qty:qty

       },

       success:function(action){

           rv = action.result;

       }

   });

   return rv;

}

实现计算服务

后台定义一个Services.ashx文件,代码如下:

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

using System;

using System.Web;

using System.Text;

using System.Data;

using System.Data.SqlClient;

using System.Collections;

using System.Collections.Generic;

public class YZDemoServices : YZServiceHandler

{

   public decimal Calc(HttpContext context)

   {

       YZRequest request = new YZRequest(context);

       decimal price = request.GetDecimal("price", 0);

       decimal qty = request.GetDecimal("qty", 0);

       return price * qty;

   }

}

Express设置

javascript('callservices',单价,数量)

Created with the Personal Edition of HelpNDoc: Free CHM Help documentation generator