简体   繁体   English

带有ASP.NET的纯Javascript应用程序

[英]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? 您认为,使用ASP.NET为纯Javascript应用程序创建服务器端的最佳方法是什么?

WCF rendering JSON? WCF呈现JSON吗? IHttpHandler? IHttpHandler的?

Update 更新

Like GMail, that runs in the browser (with a lot of Javascript) and submit and receive data with Ajax, for example. 像GMail一样,它运行在浏览器中(带有许多Javascript),并使用Ajax提交和接收数据。

In classic ASP.NET, it's fairly easy to use handlers (IHttpHandler): 在经典的ASP.NET中,使用处理程序(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: 在您的标记中,使用以下jQuery代码:

$.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. 是的,我想说一个WCF服务返回JSON。 Another option, though less intuitive, would be to use ASP.NET MVC and return JSON. 尽管不太直观,但另一个选择是使用ASP.NET MVC并返回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. 在您更新了问题之后,我真的建议您使用ASP.NET MVC,它可以使您拥有很大的灵活性,并提供您所要求的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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