簡體   English   中英

Taxee API(http://www.taxee.io/)-JavaScript-如何:POST請求和傳遞參數

[英]Taxee API (http://www.taxee.io/) - JavaScript - How To: POST Request and Pass Parameters

感謝您為我的問題提供幫助。 我一直在嘗試從此Taxee API( https://market.mashape.com/stylinandy/taxee )上的POST請求中獲取聯邦稅,州稅和FICA稅,但一直無法正常工作。 我可以使用可用於此API的兩個GET請求之一來訪問某些數據(以弄清楚該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();

但是我真正需要的數據在POST請求中。 我想知道如何訪問POST請求,更具體地說,傳遞上面鏈接中指出的參數。 多謝您提供的任何協助,我們始終感激不盡。

弄清楚實際如何做。 問題在於在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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM