[英]How can I get PHP file contents using XHR?
How can I get PHP file contents using XHR? 如何使用XHR获取PHP文件内容? 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: 我需要以文本形式获取的PHP文件内容:
$_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). 对PHP文件的HTTP请求将执行该请求并返回响应(在我的情况下为空)。 I think it is needed to set some HTTP headers.
我认为需要设置一些HTTP标头。
The only solution I found is to use simple AJAX. 我发现的唯一解决方案是使用简单的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).
我调用一些PHP文件,使用'file_get_contents()'函数获取目标PHP文件内容,并将此内容返回给客户端(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. 我发现的唯一解决方案是使用简单的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).
我调用一些PHP文件,使用'file_get_contents()'函数获取目标PHP文件内容,并将此内容返回给客户端(JS)。 But I am not pleased with this solution... Hope someone know how to make it in most elegant way.
但是我对这种解决方案不满意……希望有人知道如何以最优雅的方式进行制作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.