使用web API并得到一个引用错误
consuming a web api and getting a referenceerror
当试图从我的web api发布和获取数据时,我在浏览器中得到这个异常:
angular.js:13708 ReferenceError: $没有定义(GbyG.js:23)在对象。调用(angular.js: 4709)$controllerInit (angular.js:10234)(angular.js:9147)在复合链接fn (angular.js:8510)(angular.js:9210)在复合链接fn (angular.js:8510)在复合链接fn (angular.js:8513)在复合链接fn (angular.js:8513)at publicLinkFn (angular.js:8390)
这是我的客户端(用angular写的):
app.controller('GetSamplesByStatus',
function($scope, $http) {
var serializedData = $.param({statustype:"Received"});
$http({
method: 'POST',
url: ("http://localhost:36059/api/Samples/GetSamplesByStatus"),
data: serializedData,
headers: {
'Content-Type': 'application/json'
}}).then(function(response) {
//$scope.dataset = response;
console.log(error);
}, function(error) {
console.log(error);
});
});
我做错了什么?
参见angular文档中的$httpParamSerializerJQLike它的序列化工作类似于jQuery.param() link
.controller(function($http, $httpParamSerializerJQLike) {
//...
$http({
url: myUrl,
method: 'POST',
data: $httpParamSerializerJQLike(myData),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
});
就像这样:
app.controller('GetSamplesByStatus',
function($scope, $http, $httpParamSerializerJQLike) {
var myParams = {statustype:"Received"};
$http({
url: "http://localhost:36059/api/Samples/GetSamplesByStatus%0A",
method: 'GET',
params: myParams,
paramSerializer: '$httpParamSerializerJQLike'
}).then(function(response) {
//$scope.dataset = response;
console.log(response.data);
}, function(error) {
console.log(error);
});
});
查看这里的工作示例:http://jsbin.com/madetefeya/edit?js,console
相关文章:
- 当包含另一个asp文件时,是否也包含所有引用的样式和脚本页面
- 引用vue.js中v-for中的上一个值
- 引用“;instanceof“/来自另一个范围的原型
- 通过引用Javascript中的另一个函数来传递对象方法
- 在一个服务中引用多个API调用(Angular)
- 是否可以创建一个对象,该对象是另一个对象的子集,而不会丢失javascript中的引用
- 如何将对象引用传递到 mootools 中另一个对象的构造函数中
- 通过另一个变量引用变量名称,或从变量确定变量名称
- 如何在Javascript中将来自另一个页面的ID引用为变量
- 你能在javascript中分配一个引用表达式吗?
- 如何在 JQuery 的同一
中从另一个 引用一个 - 我如何得到一个引用我的HTML元标签
- 我如何在节点中找到一个引用网站的URL
- 对象被创建,但似乎共享一个引用
- jQuery,当移动我的jQuery代码到外部文件时,得到一个引用错误
- 用CloudKit JS创建一个引用
- 为什么总是在循环中使用对对象的最后一个引用
- 在Xcode中收到一个引用错误,说明一个对象没有定义
- 使用web API并得到一个引用错误
- 如何获得'this'在一个引用jQuery对象的函数中