How to send an HTTP request with a header parameter?

前端 未结 2 844
花落未央
花落未央 2021-02-02 00:26

I\'m very new to javascript and web programming in general and I need some help with this. I have an HTTP request that I need to send through javascript and get need to store th

2条回答
  •  长情又很酷
    2021-02-02 01:18

    With your own Code and a Slight Change withou jQuery,

    function testingAPI(){ 
        var key = "8a1c6a354c884c658ff29a8636fd7c18"; 
        var url = "https://api.fantasydata.net/nfl/v2/JSON/PlayerSeasonStats/2015";
        console.log(httpGet(url,key)); 
    }
    
    
    function httpGet(url,key){
        var xmlHttp = new XMLHttpRequest();
        xmlHttp.open( "GET", url, false );
        xmlHttp.setRequestHeader("Ocp-Apim-Subscription-Key",key);
        xmlHttp.send(null);
        return xmlHttp.responseText;
    }
    

    Thank You

提交回复
热议问题