Taxee API (http://www.taxee.io/) - JavaScript - How To: POST Request and Pass Parameters -
thanks helping out question. i've been trying federal, state, , fica tax post request on taxee api (https://market.mashape.com/stylinandy/taxee), haven't been able working. able access data (simply figure out how api works) using 1 of 2 requests available api:
var state = 'ca'; var year = 2014; var url = ' https://taxee.io/api/v1/state/'+year+'/'+state; var xmlhttp = new xmlhttprequest(); xmlhttp.open("get", url, true); xmlhttp.onload = function() { var result = json.parse(this.responsetext); console.log(result.single.income_tax_brackets); xmlhttp.abort(); } xmlhttp.send();
but data need in post request. know how access post request this, , more specifically, pass parameters noted on link above. can provide, it's appreciated.
figured out how actually. problem way parameters passed differently in post requests. helps else out there:
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 proper header information along request http.setrequestheader("content-type", "application/x-www-form-urlencoded"); http.setrequestheader("content-length", params.length); http.setrequestheader("connection", "close"); http.onreadystatechange = function() {//call function when state changes. if(http.readystate == 4 && http.status == 200) { alert(http.responsetext); } } http.send(params);
Comments
Post a Comment