[javascript] $ http get 매개 변수가 작동하지 않습니다.

왜 이것이 작동하지 않는지 아는 사람이 있습니까?

$http
    .get('accept.php', {
        source: link,
        category_id: category
    })
    .success(function (data, status) {
        $scope.info_show = data
    });

그리고 이것은 작동합니다.

$http
    .get('accept.php?source=' + link + '&category_id=' + category)
    .success(function (data, status) {
        $scope.info_show = data
    });



답변

get호출 의 두 번째 매개 변수 는 구성 객체입니다. 다음과 같은 것을 원합니다.

$http
    .get('accept.php', {
        params: {
            source: link,
            category_id: category
        }
     })
     .success(function (data,status) {
          $scope.info_show = data
     });

참고 항목 인수 의 부분 http://docs.angularjs.org/api/ng.$http을 자세히위한


답변

에서 $http.get문서 , 두 번째 파라미터는 구성 목적은 :

get(url, [config]);

GET요청 을 수행하기위한 바로 가기 방법 .

코드를 다음과 같이 변경할 수 있습니다.

$http.get('accept.php', {
    params: {
        source: link, 
        category_id: category
    }
});

또는:

$http({
    url: 'accept.php', 
    method: 'GET',
    params: { 
        source: link, 
        category_id: category
    }
});

참고로 Angular 1.6 : .success 더 이상 사용하면 .then안되므로 대신 사용하십시오.

$http.get('/url', config).then(successCallback, errorCallback);


답변