Trevor Trevor - 1 year ago 48
Javascript Question

Taxee API ( - JavaScript - How To: POST Request and Pass Parameters

Thanks for helping out with my question. I've been trying to get the federal, state, and FICA tax from a POST Request on this Taxee API (, but haven't been able to get it working. I was able to access certain data (simply to figure out how this API works) using one of the two GET requests available for this API:

var state = 'CA';
var year = 2014;
var url = ''+year+'/'+state;
var xmlhttp = new XMLHttpRequest();"GET", url, true);

xmlhttp.onload = function() {
var result = JSON.parse(this.responseText);



But the data I really need is in the POST request. I would like to know how to access a POST request for this, and more specifically, pass the parameters as noted on the link above. Thanks for any help you can provide, it's always greatly appreciated.

Answer Source

Figured out how to do it actually. The problem was the way that parameters are passed differently in POST requests. Hopefully this helps someone else out there:

  var url = '';
  var params = "filing_status=married&pay_rate=100000&state=CA";
  var http = new XMLHttpRequest();"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) {