How can I get PHP file contents using XHR? I get empty response...
const promise = new Promise(function (success, error) {
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) return;
if (xhr.status === 200) return success(xhr.responseText);
return error(new Error(`Failed lo load language data. Server response status: ${xhr.status}.`));
};
xhr.send();
}.bind(this));
PHP file contents that I need to get as text:
$_text_block_users = 'Заблокированные ученики';
$_text_id_block_user = 'ID';
$_text_firstname_lastname_block_user = 'Имя, фамилия';
$_text_group_block_user = 'Группа';
$_text_email_block_user = 'Почта';
$_text_contact_person_block_user = 'Контактное лицо';
$_text_telephone_block_user = 'Телефон';
$_text_actions_block_user= 'Действия';
HTTP request to PHP file executes it and returns response (empty in my case). I think it is needed to set some HTTP headers.
The only solution I found is to use simple AJAX. I call some PHP file, get aim PHP file contents with 'file_get_contents()' function and return this contents to the client side (JS). But I am not pleased with this solution... Hope someone know how to make it in most elegant way.
The only solution I found is to use simple AJAX. I call some PHP file, get aim PHP file contents with 'file_get_contents()' function and return this contents to the client side (JS). But I am not pleased with this solution... Hope someone know how to make it in most elegant way.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.