weixin_33725239 2011-04-05 21:16 采纳率: 0%
浏览 39

将AJAX与aspx后端一起使用?

Very new to AJAX, but have learned a bit from online tutorials. If I was using PHP all would be well, but...

...I have to use VB.Net. Microsoft provides black magic tools (in the Visual Studio IDE) for making AJAX work, but using these seems hopelessly complicated and documentation for these tools covers only the simplest examples. By contrast, writing the scripts myself seems much easier, and I will understand what is going on.

So my question is, is it possible to write my own AJAX javascript (creating the XMLHttpRequest object, etc.), and have the server-side function be written in VB.Net instead of PHP? Has anyone ever tried this?

  • 写回答

1条回答 默认 最新

  • 撒拉嘿哟木头 2011-04-05 21:19
    关注

    Of course. You can implement an HttpHandler on the server to give you full control of what happens with the request and the response. The Microsoft AJAX thing is kind of like a black magic box, but ASP.NET is not.

    Here is a starting point:

    public class MyHandler : IHttpHandler
    {
        #region IHttpHandler Members
    
        public bool IsReusable
        {
            get { return true; }
        }
    
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Write("Hello AJAX World");
        }
    }
    

    And don't forget to register the handler in the web.config ;)

    <add name="ajax_page.ashx*" 
         path="ajax_page.ashx" 
         verb="*" 
         type="MyNamespace.MyHandler, MyAssembly" />
    

    Here is my best guess at what this should look like in VB.NET (NOTE: I have never written a single line of VB.NET)

    Public class MyHandler 
        Inherits IHttpHandler
    
        Public Property IsReusable() As Boolean
            Get
                Return True
            End Get
        End Property
    
        Public Sub ProcessRequest(ByVal context as HttpContext)
            context.Response.Write("Hello AJAX World")
        End Sub
    End Class
    
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大