Taxee API(http://www.taxee.io/) - JavaScript - 如何:POST请求和传递参数

时间:2016-01-15 22:46:50

标签: javascript api post xmlhttprequest

感谢您帮助解决我的问题。我一直试图从这个Taxee API(https://market.mashape.com/stylinandy/taxee)上的POST请求中获得联邦,州和FICA税,但是无法使其正常运行。我能够使用这个API可用的两个GET请求之一访问某些数据(只是为了弄清楚这个API是如何工作的):

{{1}}

但我真正需要的数据是在POST请求中。我想知道如何访问POST请求,更具体地说,传递上面链接中提到的参数。感谢您提供的任何帮助,我们非常感谢。

1 个答案:

答案 0 :(得分:0)

想出如何实际做到这一点。问题是在POST请求中以不同方式传递参数的方式。希望这有助于其他人:

  var url = 'https://taxee.io/api/v1/calculate/2014';
  var params = "filing_status=married&pay_rate=100000&state=CA";
  var http = new XMLHttpRequest();


  http.open("POST", url, true);

  //Send the proper header information along with the request
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http.setRequestHeader("Content-length", params.length);
  http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
  if(http.readyState == 4 && http.status == 200) {
    alert(http.responseText);
  }
}
http.send(params);