0

this is my code:

var PID = (this.settings.id);
var MySeatString = 'null';

var xmlhttp = new XMLHttpRequest();
var url = 'http://localhost:14481/Fa/DBStuff.aspx?PID=' + PID;
xmlhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    var arr = JSON.parse(this.responseText);
    var i;
    var out = '';
    if (arr[0].Situ == 'ok') {
      MySeatString = arr[0].Seat;
    } else {
      alert('error: ' + arr[0].Situ);
    }
  }
}

xmlhttp.open('POST', url, true);
xmlhttp.send();
alert(MySeatString);

the problem is MySeatString = null in the end of the code. But arr[0].Seat = available how can i access arr[0].Seat after xmlhttp.send(); I'm new to java script. thank you.

Robin Mackenzie
  • 18,801
  • 7
  • 38
  • 56
Mahdi Hesari
  • 323
  • 9
  • 28

0 Answers0