[英]Uncaught Error: [$http:badreq] Http request configuration url must be a string (AngularJS)
I am developing a webapp,and have ran into some difficulties, especially this one that I am having a hard time getting rid of, here is the code 我正在开发一个webapp,并遇到了一些困难,尤其是这个我很难摆脱的问题,这里是代码
this.bookSpace = function (date, spaceId) {
swal({
title: "Are you sure?",
text: "Would you like to book this space?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, Book it!",
closeOnConfirm: false
},
function () {
var transform = function (data) {
return $.param(data);
};
$http.post(
{
url:"/api/api/AdhocBooking?bookingDate="+date.DateTime+"&spaceId="+spaceId,
headers: {'content-type': 'application/json; charset=UTF-8','Authorization': 'bearer'},
transformRequest: transform,
data: {
"Name": "Michael Knott"
}
});
swal("Booked!",
"Your space has been booked!",
"success");
})
Here is the response I get 这是我得到的回应
Uncaught Error: [$http:badreq] Http request configuration url must be a string
未捕获的错误:[$ http:badreq] Http请求配置url必须是一个字符串
Thank you. 谢谢。
First you will need to replace date.DateTime to be encodeURIComponent(date.DateTime.toString()) there is another point in the code posted I don't see a reason for this function. 首先,你需要将date.DateTime替换为encodeURIComponent(date.DateTime.toString())在发布的代码中有另一个点我没有看到这个函数的原因。
function () {
var transform = function (data) {
return $.param(data);
};
as data you passed is already json 你传递的数据已经是json了
headers: {'content-type': 'application/json; charset=UTF-8','Authorization': 'bearer'},
transformRequest: transform,
data: {
"Name": "Michael Knott"
}
you can remove transformRequest function in the backed also you will need to decode date.DateTime in the backend if you want to use it. 您可以删除备份中的transformRequest函数,如果要使用它,则需要在后端解码date.DateTime。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.