search

Home  >  Q&A  >  body text

angular.js - angularjs每次发送$http都把所有数据当作一个key,value为空发出去


chrome浏览器中的发送数据如上图,注意最后那个冒号,冒号前面是key,后面value是空的。
我的发送代码如下:

$scope.loginJump = function(info){
    $http({
        url:'http://192.168.1.54:8080/retailer/user/auth',
        method:"POST",
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: {
            userName: info.staffID,
            userPass: info.password,
            checkCode: info.security
        },
        success: function(data){
            alert(data);
        },
        error: function(err){
            alert(err);
        }
    });
};
某草草某草草2743 days ago521

reply all(1)I'll reply

  • 漂亮男人

    漂亮男人2017-05-15 16:53:56

    Putting it directly in data will send the parameters directly to the body in the form of json, and your headers are set to the content-type of application/x-www-form-urlencoded, so it will be considered formdata. , but actually the whole thing is used as a key.

    Of course, it’s no problem to post the data directly using json. If you must post form data, you should spell it out yourself or use jquery’s $.param or other methods to do it.

    reply
    0
  • Cancelreply