从ResponseText中提取值

时间:2017-08-04 04:27:56

标签: javascript json rest

需要以下代码的帮助。它的工作正常,但我需要从返回信息中提取并仅提供一个值,例如我如何只提取" nextRun"价值来自:



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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

数据存储的网址似乎存在问题。看看这个:

&#13;
&#13;
sns.distplot(df['MEDV']/100)
plt.show()
&#13;
    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);
&#13;
&#13;
&#13;

看起来真正的问题是request_.readyState不等于4.