Hi,
how to capture the received result from a sent ajax request?
I have a script in which I send an ajax request to the server. When I call the script in the form of text like: return test223. I will get this result, but when I want to capture the received result from ajax so it no longer works ... I tried to wait a few seconds but it also did not give any effects ...
Skrypt:
$stringRequest = 'let http = new XMLHttpRequest();';
$stringRequest .= 'var url = "adres www";';
$stringRequest .= 'http.open("POST", url, true);';
$stringRequest .= 'http.setRequestHeader("Accept", "application/json, text/plain, */*");';
$stringRequest .= 'http.setRequestHeader("Content-Type", "application/json;charset=utf-8");';
$stringRequest .= 'http.setRequestHeader("X-XSRF-TOKEN", "'.$xsrf.'");';
$stringRequest .= 'http.send(JSON.stringify(parameters));';
$stringRequest .= 'http.onload = function() { if (http.status != 200) { return 'error';} else {return http.response;}};';
$stringRequest .= 'http.onprogress = function(event) {if (event.lengthComputable) {console.log(`Received ${event.loaded} of ${event.total} bytes`);} else {console.log(`Received ${event.loaded} bytes`);}};';
$stringRequest .= 'http.onerror = function() {return "Request failed";};';
$result = $driver->executeScript($parameters);
while (true) {
echo 'Oczekiwanie na dane... '.PHP_EOL;
if($result) {
print_r($result); break;
}
}