- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经创建了一个 ASP.Net API Controller ,我正在尝试使用 Angular 向它发出 POST 请求。请求到达我的 Controller 方法,但参数值为空。
我的 Angular 代码:
$http({ method: 'POST', url: '/api/Contents', data: "value=foobar", headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).
success(function(data) {
}).
error(function(data, status, headers, config) {
});
$http({ method: 'POST', url: '/api/Contents', data: { "foo": "bar", "foo2": "bar2" }, headers: { 'Content-Type': 'application/json'} }).
success(function(data) {
}).
error(function(data, status, headers, config) {
});
public void Post([FromBody]string value)
{
//But Value is NULL!!!!!!
}
最佳答案
像这样:
$http({
method: 'POST',
url: '/api/Contents',
data: "=foobar",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function(data) {
}).error(function(data, status, headers, config) {
});
=foobar
数据参数。在这种情况下,您不应指定参数名称。是的,我知道,别问了。
how model binding in the Web API works
.如果你像我一样发现这绝对是疯了,你可以考虑使用
ServiceStack
反而。
public class ContentsModel
{
public string Value { get; set; }
}
public void Post(ContentsModel model)
{
}
$http({
method: 'POST',
url: '/api/Contents',
data: JSON.stringify({ "value": "the value" }),
headers: { 'Content-Type': 'application/json' }
}).success(function(data) {
}).error(function(data, status, headers, config) {
});
JSON.stringify
将 javascript 对象转换为 JSON 字符串的方法。
关于ajax - 对 Asp.Net Web API 的 Angular Xhr 发布请求导致参数为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16151566/
这可能是一个非常明显的问题,但请解释一下 xhr 和 xhr.upload 之间的区别是什么? 我的用例是我正在将文件上传到服务器,但假设服务器出现故障。在这种情况下,我应该处理 xhr.onerro
这是我的场景: 我有一个 URL,可以生成管理工作区的大量导出 - 它通常约为 3mb,需要约 15 秒才能生成。 当前的实现是对按钮上带有 download 属性的 URL 的正常同步请求,以强制下
我正在执行 XMLHttpRequest,如果失败,我想回退到执行其他操作(读取本地文件),但我想在 XHR 函数 (getDBfileXHR) 本身之外执行此操作。 我也在使用 Jquery。 考虑
XMLHttpRequest 实例上有五个事件。 var xhr = new XMLHttpRequest(); xhr.onloadstart = res => { console.log(
xhr.open('put',url,false) xhr.upload.addEventListener('load',function(e){alert(xhr.responseText)},fa
我正在尝试 promisify the native XHR , 现在问题来了,当我使用下面的代码时: function request(method, url) { return new P
我想知道.. 我怎样才能得到 XHR finished loading 字符串? 基本上,我在 Google instant 的页面上,我想以字符串的形式返回搜索结果的“真实”URL。 最佳答案 如果
是否可以在 XMLHttpRequest 的 onreadystatechange 处理程序中找到作为参数发送到 XMLHttpRequest 的 send(data) 函数的数据?我认为此时它必须存
当我在 xhr.then() 中返回“结果”并且我使用 dojo 1.10.4 时遇到一些问题,请帮助我! 以下代码在dojo中使用xhr('dojo/request/xhr')连接到API: rem
这个问题在这里已经有了答案: How to structure nested Promises (3 个答案) 关闭 6 年前。 我需要做一个 promise 序列。我想使用基于标准的方法(ES6?
当执行“GET”请求时,xhr.response 和 xhr.responseText 都返回相同的值。有什么不同?有吗? 最佳答案 response 被解释为 ArrayBuffer、Blob、Do
我只需要支持主要的现代浏览器(IE10+、FF、Chrome、Safari) 我可以做这个替换吗,因为我想简化我的代码库: 来自: xhr.onreadystatechange = function
DataTables 版本:1.10.20 我目前正在使用 pipeline plugin并聆听 xhr event 。 xhr 事件按预期触发,但是回调中的 xhr 参数未定义。设置对象中还有一个
在非常高的级别上,我们单击一个命令建筑物控制点的按钮;打开或关闭灯。单击应该向服务器发送 POST 请求。问题是有时单击按钮但 POST 请求不会发出。该按钮没有指示它是否已被单击的功能(小幅增强)。
我正在尝试使用 youtube v3 API 上传视频,查看 this示例。 所以,我写了这样的东西: var xhr = new XMLHttpRequest(); xhr.open('PUT',
我正在使用 XHR GET 获取 Blade html 并尝试缓存它,这样它就不需要每次都去服务器下载它。这是我的代码。 但这不起作用并且总是转到服务器。 $.ajax({ method: "
我正在尝试为文件上传创建一个进度条,但由于某种原因,XHR 进度响应仅在最后触发一次。但是,如果我打开 firebug 窗口,它可以 100% 正常工作(在文件上传过程中触发)。我正在本地主机上测试它
我正在尝试获取 xhr 请求。 (该脚本应每 2 秒循环运行一次)这是我的脚本: function getJson() { var xhr = new XMLHttpReque
我有一个简单的 XHR 来加载“testdirectory/testpage.html” var xhr; (XMLHttpRequest) ? xhr= new XMLHttpRequest() :
我正在使用XHR npm 上的 lib 用于在 JS 应用程序的客户端发出 ajax 请求。我的代码如下所示: xhr({uri: "http://foo"},function (err, resp,
我是一名优秀的程序员,十分优秀!