2017-03-18 107 views
0
$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); 
      } 
     }); 

當我使用此代碼我的鉻發送:

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

但是,當我在laravel使用相同的代碼本地主機服務:8000我得到:

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

我沒有任何更多$ http配置,只有請求中的這個頭部選項。在請求之前,我在控制檯上沒有錯誤,所以我認爲我的代碼是可以的。我的服務器有什麼問題嗎?

+0

當您使用'POST'時,您應該使用'data'而不是'param' –

回答

5

代碼表示發出請求的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請求。

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