[英]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
這很可能是由以下原因引起的:
Location
頭重定向到不帶/
的末尾的同一URL 如果您查看請求列表,則應該看到POST請求。
要解決此問題,您需要查看發出重定向的服務器端代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.