如何调用ASHX处理程序,并得到结果返回 [英] how to call ASHX handler and getting the result back
问题描述
我创建了一个处理程序而做一些数据库的工作后返回整数值。我想知道我如何能得到这个值,并指定该值通过调用处理程序的标签。
我GOOGLE了它和大多数例子中使用Jquery.AJAX调用来检索值。我相信我也可以通过使用获得的价值。但在我公司的一些限制,我是受限制的使用code后面。
任何例子会有所帮助。
处理程序:http://somesite.com/Stores/GetOrderCount.ashx?s$c$c=VIC
返回:3
需要把这个分配给一个标签控件
我已经试过这么多这么远。</ P>
HttpWebRequest的要求=(HttpWebRequest的)WebRequest.Create(http://somesite.com/Stores/GetOrderCount.ashx?s$c$c=VIC);
HttpWebResponse响应=(HttpWebResponse)request.GetResponse();
Label1.Text = response.ToString()//这不起作用
使用<一个href=\"http://msdn.microsoft.com/en-us/library/fhd1f0sw%28v=vs.80%29.aspx\">WebClient.DownloadString
Web客户端的客户端=新的WebClient();
Label1.Text = client.DownloadString(http://somesite.com/Stores/GetOrderCount.ashx?s$c$c=VIC);
您也可以使用AJAX直接调用处理和更新的标签。
下面是一个jQuery例如:
$。获得(商店/ GetOrderCount.ashx?s code = VIC'功能(数据){
$('。结果')HTML(数据)。
});
I have created a Handler which return integer value after doing some database work. i would like to know how can i get that value and assign that value to Label by calling that handler.
I have googled it and most of the example uses Jquery.AJAX calls to retrieve the value. I am sure i can also get the value by using that. BUT for some limitation in my company i am restricted to use code behind.
Any example will help.
Handler: http://somesite.com/Stores/GetOrderCount.ashx?sCode=VIC
which returns: 3
need to assign this to a label control
i have tried this much so far.
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://somesite.com/Stores/GetOrderCount.ashx?sCode=VIC");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Label1.Text = response.ToString() // this does not work
WebClient client = new WebClient ();
Label1.Text = client.DownloadString ("http://somesite.com/Stores/GetOrderCount.ashx?sCode=VIC");
You could also directly call your handler using ajax and update the label.
Here is a jQuery example:
$.get('Stores/GetOrderCount.ashx?sCode=VIC', function(data) {
$('.result').html(data);
});
这篇关于如何调用ASHX处理程序,并得到结果返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!