简体   繁体   中英

Pure Javascript application with ASP.NET

In your opinion, what's the best way to create the server side to a pure Javascript application with ASP.NET?

WCF rendering JSON? IHttpHandler?

Update

Like GMail, that runs in the browser (with a lot of Javascript) and submit and receive data with Ajax, for example.

In classic ASP.NET, it's fairly easy to use handlers (IHttpHandler):

context.Response.ContentType = "application/json"
context.Response.Clear()
context.Response.AddHeader("Pragma", "no-cache")
context.Response.AddHeader("Expires", "-1")
context.Response.Write(myJsonString)

In your markup, use the following jQuery code:

$.ajax({
    type: "GET",
    url: "GetTasksForTaskSet.ashx?tasksetid=" + guid,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(data) {
        for(var i = 0; i < data.length; i++) {
            // do something
        },
    error: function(){ alert('error'); }
});

Yeah, I'd say a WCF service returning JSON. Another option, though less intuitive, would be to use ASP.NET MVC and return JSON.

After your updated question, I would really recommend ASP.NET MVC it will allow you to have a ton of flexibility, and provide exactly what your asking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM