将角度HTTP数据变量之一设置为布尔值



编辑:这可能是后端API的问题吗?$ .param以$ .param的方式发送的数据请求总是字符串,对吗?所以他们需要在后端解析这些东西?

我目前正在尝试向API发送邮政请求以注册用户。要求之一是接受条款和条件和年龄要求,它预计这是布尔值。

我相信问题可能是$ http请求是向API后端发送字符串而不是布尔值,因此它拒绝了。我如何通过$ http发送布尔值?

    var apiCall = {
      method: 'POST',
      url: 'API_URL',
      data: $.param({
        'user[email]': username,
        'user[password]': password,
        'user[password_confirmation]':password,
        'profile[age_acceptance]': ageAcceptance,
        'profile[terms_acceptance]': termsAcceptance
      }),
      headers: {
        'Accept': 'application/vnd.softswiss.v1+json',
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      transformRequest: function(data, headersGetter, status) {
        console.log(data);
        console.log(headersGetter(data));
      }
    }
var dataToPost = JSON.stringify( {
    'user[email]': username,
    'user[password]': password,
    'user[password_confirmation]':password,
    'profile[age_acceptance]': ageAcceptance,
    'profile[terms_acceptance]': termsAcceptance
  });
  data: dataToPost,
  headers: {.......,
   .....

您必须串制参数。

JSON.stringify(params)

最新更新