簡體   English   中英

未捕獲的錯誤:[$ http:badreq] Http請求配置url必須是一個字符串(AngularJS)

[英]Uncaught Error: [$http:badreq] Http request configuration url must be a string (AngularJS)

我正在開發一個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");
  })

這是我得到的回應

未捕獲的錯誤:[$ http:badreq] Http請求配置url必須是一個字符串

謝謝。

首先,你需要將date.DateTime替換為encodeURIComponent(date.DateTime.toString())在發布的代碼中有另一個點我沒有看到這個函數的原因。

function () {
    var transform = function (data) {
      return $.param(data);
    };

你傳遞的數據已經是json了

headers: {'content-type': 'application/json; charset=UTF-8','Authorization': 'bearer'},
        transformRequest: transform,
        data: {

          "Name": "Michael Knott"
        }

您可以刪除備份中的transformRequest函數,如果要使用它,則需要在后端解碼date.DateTime。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM