簡體   English   中英

Angular $ http發送get而不是post

[英]Angular $http sends get instead of post

$http.post(main+'/api/getcard/', $.param({number: $scope.searchcard}), {headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'} })
        .then(function (response) {
            if(response.data != 0)
            {
                $location.path('/redeem/'+response.data.id);
                console.log(response.data);
            }
        });

當我使用此代碼時,我的chrome發送:

Request URL:http://cards.mporeda.pl/branch/api/getcard
Request Method:GET
Status Code:405 Method Not Allowed

但是當我在laravel服務localhost:8000上使用相同的代碼時,我得到:

Request URL:http://localhost:8000/branch/api/getcard/
Request Method:POST
Status Code:200 OK

我在請求中沒有任何更多的$ http配置。 在此請求之前我在控制台上沒有錯誤,所以我問我的代碼是否正常。 我的服務器有什么問題嗎?

您的代碼發出請求的URL是:

main+'/api/getcard/'

您的請求所使用的網址是:

Request URL:http://cards.mporeda.pl/branch/api/getcard

這很可能是由以下原因引起的:

  1. 您對嘗試發出POST請求的URL發出POST請求
  2. 服務器以301或302狀態響應,並且Location頭重定向到不帶/的末尾的同一URL
  3. 重定向后的瀏覽器並發出GET請求

如果您查看請求列表,則應該看到POST請求。

要解決此問題,您需要查看發出重定向的服務器端代碼。

暫無
暫無

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

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