AngularJs $http.post() does not send data

前端 未结 30 1831
我在风中等你
我在风中等你 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条回答
  •  梦毁少年i
    2020-11-22 03:34

    In my case I resolve the problem like this :

    var deferred = $q.defer();
    
    $http({
        method: 'POST',
        url: 'myUri', 
        data: $.param({ param1: 'blablabla', param2: JSON.stringify(objJSON) }),
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    }).then(
        function(res) {
            console.log('succes !', res.data);
            deferred.resolve(res.data);
        },
        function(err) {
            console.log('error...', err);
            deferred.resolve(err);
        }
    );
    return deferred.promise;
    

    You need to use JSON.stringify for each param containing a JSON object, and then build your data object with "$.param" :-)

    NB : My "objJSON" is a JSON object containing array, integer, string and html content. His total size is >3500 characters.

提交回复
热议问题