简体   繁体   中英

Extracting value from ResponseText

Need a help with the below code. it's working just fine, but I need to extract and present only one value from the return info, for example how I can extract only the "nextRun" value from:

 function CallWebAPI() { var token_ = "*Token*" var request_ = new XMLHttpRequest(); request_.onreadystatechange=function(){ if (request_.readyState===4){ document.getElementById("demo").innerHTML = request_.responseText; } } request_.open("GET", "https://192.168.33.42:4443/v1/Jobs", true); request_.setRequestHeader('Access-Control-Allow-Origin',''); request_.setRequestHeader('Content-Type', 'application/json') request_.setRequestHeader('Cache-Control', 'no-cache'); request_.setRequestHeader("Authorization", "Bearer "+ token_); request_.send(); } 
 <h1 id="demo">Must be here</h1> <button onclick="document.getElementById('demo').innerHTML=CallWebAPI()">Get Token</button> 

There seems to be problem with the url that the data is stored. Check this out:

  function CallWebAPI() { var token_ = "*Token*" var request_ = new XMLHttpRequest(); request_.onreadystatechange=function(){ console.log(request_.readyState === 4) // readyState is false if (request_.readyState===4){ console.log(request_.responseText) document.getElementById("demo").innerHTML = request_.responseText; } } request_.open("GET", "https://192.168.33.42:4443/v1/Jobs", true); request_.setRequestHeader('Access-Control-Allow-Origin',''); request_.setRequestHeader('Content-Type', 'application/json') request_.setRequestHeader('Cache-Control', 'no-cache'); request_.setRequestHeader("Authorization", "Bearer "+ token_); request_.send(); } document.getElementById("checkAllTopicCheckBoxes").addEventListener ("click", CallWebAPI, false); 
 <h1 id="demo">Must be here</h1> <button id="checkAllTopicCheckBoxes"> Get Token</button> 

It looks like the real problem is that request_.readyState does not equal to 4.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM