weixin_33743661 2014-08-15 00:12 采纳率: 0%
浏览 33

angularjs json标头请求

if I do this I can get a data .. but, it's not json..

     var url = 'inputtest.php';
     $http({
         method: 'POST',
         url: url,
         data: $.param($scope.company),
         headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
        }).success(function(response){
            console.log(response);
        });

so, if I change like this

           headers: { 'Content-Type': 'application/json; charset=UTF-8'}

I don't get any parameter from it.

===> headers info says "Request Payload" ?? instead of Request Data

server side. just testing it.

          echo json_encode($_REQUEST); 

I don't know what's wrong and how to fix it.

Any advice ?

  • 写回答

2条回答 默认 最新

  • 程序go 2014-08-15 00:25
    关注

    i think it's not a javascript problem but more a server side issue.

    You should try to add header('Content-Type: application/json'); before your echo in your php file

    评论

报告相同问题?