从代码隐藏调用ASP.NET Web API
发布时间:2020-12-05 02:48:47 所属栏目:asp.Net 来源:互联网
导读:我如何直接从代码隐藏调用ASP.NET Web API?还是应该调用我的 javascript函数,从代码隐藏中调用get JSON方法? 我通常有如下的东西: function createFile() { $.getJSON(api/file/createfile, function (data) { $(#Result).ap
我如何直接从代码隐藏调用ASP.NET Web API?还是应该调用我的 javascript函数,从代码隐藏中调用get JSON方法? 我通常有如下的东西: function createFile() { $.getJSON("api/file/createfile",function (data) { $("#Result").append('Success!'); }); } 任何指针赞赏. TIA. *我正在使用WebForms. 解决方法如果您必须调用Web服务本身,您可以尝试使用HttpClient as described by Henrik Neilsen.Updated HTTPClient Samples 一个基本的例子: // Create an HttpClient instance HttpClient client = new HttpClient(); // Send a request asynchronously continue when complete client.GetAsync(_address).ContinueWith( (requestTask) => { // Get HTTP response from completed task. HttpResponseMessage response = requestTask.Result; // Check that response was successful or throw exception response.EnsureSuccessStatusCode(); // Read response asynchronously as JsonValue response.Content.ReadAsAsync<JsonArray>().ContinueWith( (readTask) => { var result = readTask.Result //Do something with the result }); }); (编辑:鲜蔬坊站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 中国网通新版400电话 - 企业直线
- asp.net-mvc-2 – 使用’class(或其他保留关键字)作为匿名类
- ASP.Net – AJAX UpdatePanel中的Javascript
- asp.net – 将appsettings.production.json发布到azure上
- asp.net-mvc – 为什么我的视图模型中的内部成员无法在视图
- asp.net – 如何使用ajax调用跨域web api?
- asp.net – Ajax Control Toolkit正在加载太多脚本资源
- 将搜索框添加到ASP.Net动态数据列表页面
- asp.net – jquery getJson没有将任何值传递给控制器
- asp.net – Silverlight初始化错误2110 Internet Explorer
推荐文章
站长推荐
- asp.net – Session Timeout .NET
- ASP.NET中XML转JSON的方法实例
- asp.net – 在MVC3或IIS 7.5中禁用x-frame-optio
- asp.net-mvc – MVC 5具有身份验证模式的外部身份
- 在asp.net中将用户变量存储在数据库与会话中
- WPF中ComboBox绑定数据库自动读取产生数据
- asp.net-mvc – Url.Action生成查询字符串,以任何
- ASP.NET:从C#代码隐藏显示警报
- asp.net-web-api – WebAPI:403在发布网站后被禁
- asp.net-mvc-3 – System.Web.Mvc.HandleErrorIn
热点阅读