Git Product home page Git Product logo

ajaxframework's Introduction

AjaxFramework

#A Framework about ajax in donnet

#####Do you hate so many *.ashx file in your web project?
#####Do you like visit the general c# method by ajax but not like webservice?
Now AjaxFramewok can help you do it.you only need reference the AjaxFramework.dll and Wirte the Attribute before the head of method,the method is change to be a web method and you can visit it by url or by ajax.


Example(these method is in class "data"):

[WebMethodAttr(RequestType.Get)]
public float Add(float a, float b)
{
     return a + b;
}

Now you can visit this method by url:http://domain.com/data/add.ajax?a=x&b=y

Also,this Framework has supplied other Attribute like WebParameterAttr,OutputCacheAttr and so on,

[WebMethodAttr(RequestType.Get)]
[WebParameterAttr("a", typeof(float), MinValue = 5)]
[WebParameterAttr("b",typeof(float),RegexText=@"^[0-9]{1,3}[\.][0-9]{1,3}$",ErrorMsg="b must be a decmail")]
public float Add(float a, float b)
{
     return a + b;
}

[WebMethodAttr(RequestType.Get)]
[OutputCacheAttr(20)]
public string Get_Pat2()
{
     return "pat" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
}

You can define your Attribute only inherit the abstract class of ValidateAttr.

Oh,It is no easy. If the returnType of method is not a sample type.the program the Serializate it to json.

[WebMethodAttr(RequestType.Get)]
public DataTable Get_Data()
{
      DataTable dt = new DataTable("dt");
      dt.Columns.Add("id");
      dt.Columns.Add("name");

      DataRow row = dt.NewRow();
      row["id"] = 1;
      row["name"] = "tom";
      dt.Rows.Add(row);

      DataRow row2 = dt.NewRow();
      row2["id"] = 2;
      row2["name"] = "peter";
      dt.Rows.Add(row2);

      return dt;
}

it will show in the page for json code.


Now ,How use the framwork,it is easy.
you only config it in web.config and add the httphandler of AjaxHandlerFactory

//IIS6.0
<add verb="*" path="*.ajax" validate="true" type="AjaxFramework.AjaxHandlerFactory,AjaxFramework" />
//IIS7.0
<add name="ajaxhandler" verb="*" preCondition="integratedMode" path="*.ajax"  type="AjaxFramework.AjaxHandlerFactory,AjaxFramework"/>

Do you han any question that you can write in this project.
Welcome to develop this project together.

ajaxframework's People

Contributors

512948935 avatar yyl8781697 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.