如何调用ASHX处理程序并返回结果
我创建了一个Handler,在执行一些数据库工作后返回整数值。 我想知道如何通过调用该处理程序获取该值并将该值赋给Label。
我用google搜索它,大多数示例使用Jquery.AJAX调用来检索值。 我相信我也可以通过使用它获得价值。 但由于我公司的某些限制,我被限制使用代码。
任何例子都会有帮助。
Handler: https://somesite.com/Stores/GetOrderCount.ashx?sCode=VIC which returns: 3
需要将其分配给标签控件
到目前为止,我已经尝试了这么多。
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("https://somesite.com/Stores/GetOrderCount.ashx?sCode=VIC"); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Label1.Text = response.ToString() // this does not work
使用WebClient.DownloadString
WebClient client = new WebClient (); Label1.Text = client.DownloadString ("https://somesite.com/Stores/GetOrderCount.ashx?sCode=VIC");
您也可以使用ajax直接调用您的处理程序并更新标签。
这是一个jQuery示例:
$.get('Stores/GetOrderCount.ashx?sCode=VIC', function(data) { $('.result').html(data); });
试试这个
上述就是C#学习教程:如何调用ASHX处理程序并返回结果分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
System.IO.Stream stream = response.GetResponseStream(); System.IO.StreamReader reader = new System.IO.StreamReader(stream); string contents = reader.ReadToEnd();
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1022392.html