19WAS85
19WAS85

Reputation: 2863

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.

Upvotes: 1

Views: 550

Answers (2)

Nate
Nate

Reputation: 30646

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.

Upvotes: 1

Peter
Peter

Reputation: 14108

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'); }
});

Upvotes: 2

Related Questions