Guest User

Untitled

a guest
Oct 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. function pushDatatoServer(){
  2. baseURL = 'localhost'
  3. port = app_port
  4. endpoint = '/push'
  5. url = 'http://'+baseURL+':'+port+endpoint
  6. console.log(url)
  7. xhttp = new XMLHttpRequest()
  8. xhttp.open("POST",url , true);
  9. xhttp.setRequestHeader("Content-type", "application/json");
  10. xhttp.setRequestHeader("secretKey", "xSecretx");
  11. xhttp.onreadystatechange = function(){
  12. if(xhttp.readyState === 4 && xhttp.status === 200){
  13. var res = JSON.parse(xhttp.responseText);
  14. console.log(res)
  15. document.getElementById("final_result").innerHTML = res['riskScore'];
  16. //var maxval = 100;
  17. //var minval = 0;
  18. //var moreisgood = false;
  19. //var col = rgbify(maxval, minval, val, moreisgood)
  20. var score = res['riskScore'];
  21. if(score >= 0 && score <= 30 ){
  22. var val = rgb(152,209,84);
  23. }
  24. else if (score >= 30 && score <=70){
  25.  
  26. var val = rgb(253,179,74);
  27. }
  28. else {
  29. var val = rgb(255,107,107);
  30. }
  31.  
  32. $("#final_result").css("background-color", val);
  33. }
  34. }
  35. console.log(currentState)
  36. xhttp.send(JSON.stringify(currentState));
  37. }
  38.  
  39. <div class="endspan1" align="right">
  40. <input type="button" class=" button1" value="Get Score" onclick="pushDatatoServer()" id="pushDatatoServer">
  41. </div>
  42.  
  43. <span type="text" class="resultField" id="final_result" readonly ></span
Add Comment
Please, Sign In to add comment