AngularJs $http.post() does not send data

前端 未结 30 2516
我在风中等你
我在风中等你 2020-11-22 02:51

Could anyone tell me why the following statement does not send the post data to the designated url? The url is called but on the server when I print $_POST - I get an empty

30条回答
  •  面向向阳花
    2020-11-22 03:29

    I also faced similar problem and i was doing something like this and that didn't worked. My Spring controller was not able read data parameter.

    var paramsVal={data:'"id":"1"'};
      $http.post("Request URL",  {params: paramsVal});  
    

    But reading this forum and API Doc, I tried following way and that worked for me. If some one also have similar problem, You can try below way as well.

    $http({
          method: 'POST',
          url: "Request URL",           
          params: paramsVal,
          headers: {'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'}
                });
    

    Please check https://docs.angularjs.org/api/ng/service/$http#post for what param config does. {data:'"id":"1"'} – Map of strings or objects which will be turned to URL?data="id:1"

提交回复
热议问题