0

the code i am trying to run

<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>

<script> 
var http = new XMLHttpRequest();
var params = 'frashnum=&action=login&Frm_Logintoken="+results+"&Username=admin&Password=test';
var url = 'http://page/';
http.open('POST', url, true);
//Send the proper header information along with the request
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');


 http.onload = function () {

let str = (http.responseText);
    alert(str)
    let pattern =/\bgetObj\("Frm_Logintoken"\)\.value = "([^"]+)";/;
    let results = console.log(str.match(pattern)[1]);
    return results;

 } 
 console.log(results);
http.send(params);
</script>
</body>
</html>

i am trying to return the results variable to use it in Frm_Logintoken from the params but it says results is not defined . where clearly it's defined... so i tried to remove the equals sign before the
function and this part too http.onload = and it worked but the rest of code didn't ... so is there a way to fix this ?

mina nageh
  • 143
  • 2
  • 2
  • 13
  • I wouldn't return it instead I would call your `Frm_Logintoken` function from within the `onload` and pass `results` as a parameter. If you can't do that, at the top of your script outside of ALL functions `var results;' then don't return it, but still call your `Frm_Logintoken` from within the `onload`. – imvain2 Jun 10 '19 at 15:35
  • @imvain2 but how can i call Frm_Logintoken ? it's not a function it's just one of the parameters ..... and isn't this `var results;` will make it undefined ? – mina nageh Jun 10 '19 at 15:42
  • mate @imvain2 i tried that code and it doesn't work !!!!!!!!!! – mina nageh Jun 11 '19 at 06:25

0 Answers0