【发布时间】:2014-12-25 10:17:22
【问题描述】:
我要将我的字符串发布到 api,但每次我都遇到这样的错误。但是,通过提琴手它工作正常
NetworkError: 404 Not Found - http://localhost:3094/api/Controller/Action/
这是我的js代码
var deferred = $q.defer();
$http.post('http://localhost:3094/api/Country/GetSelectionCount/' ,
{id:selection})
.success(function (data, status, headers, config) {
deferred.resolve(data);
})
.error(function (data, status, headers, config) {
deferred.reject(data);
});
return deferred.promise;
和服务器代码
[AcceptVerbs("GET")]
[ActionName("GetSelectionCount")]
public IHttpActionResult GetSelectionCount(string id)
{
if (String.IsNullOrWhiteSpace(id))
return NotFound();
var result= (from m in db.Products
where m.ProductName.Contains(id)
select m).Count();
return Ok(result);
}
【问题讨论】:
-
您正在发帖,但服务器代码说只获取?
-
对不起,不提这些代码了:)这只是简单的测试代码,所以我才这样调用,重点是,这个GetSelectionCount函数从UI中获取一个参数并返回一些数据到客户端。如果我将 [AcceptVerbs("GET")] 更改为 [AcceptVerbs("POST")] 或 [HttpPost] 属性,无论如何它都不起作用(((
-
我有另一篇文章正在运行,但在这篇文章中出现错误
标签: angularjs api http-post httprequest