$http.post not working in AngularJS

后端 未结 4 1605
别那么骄傲
别那么骄傲 2021-01-12 03:09

When I use $http.get my code works, but if I use $http.post, I never get the parameters to the request .php file.

This is Service function:

         


        
4条回答
  •  暖寄归人
    2021-01-12 03:50

    $http({
        method: 'POST',
        url: 'http://mtapi.azurewebsites.net/api/sectiontype',
        dataType: 'json',
        data: {SectionTypeId:0, Name: $scope.message},
        headers: { 'Content-Type': 'application/json; charset=UTF-8' }
    }).success(function (data) {
        alert(data);
    }).error(function (data) {
        alert(data);
    });
    

    headers must be added in the end of the array otherwise it won't work.

提交回复
热议问题