У меня на сервере есть сценарий php, который выполняет несколько задач (настройка папок, копирование файлов и т. Д. c), и я вызываю сценарий с помощью ajax.
т.е.
регистрация. js:
const evtSource = new EventSource("/createuser.php", { withCredentials: true } );
evtSource.onmessage = function(event) {
console.log(event.data);
}
$.ajax({
type: 'POST',
url: '/createuser.php',
dataType: 'json',
data: {
'username': "test user",
'usertype' : "author"
},
success: function(data){
console.log("user created");
}
});
сейчас на сайте createuser. php Я пытаюсь отправить сообщение на мою веб-страницу:
createuser. php:
<?php
function SendProgressMessage($op){
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
switch($op){
case "userCreated":
echo "User Created";
break;
case "foldersCreated":
echo "Folder structure created";
break;
case "TemplatesCopied":
echo "Templates Copied";
break;
}
flush();
}
?>
Могу ли я установить evtSource для того же сценария и вызова ajax или в сценарии создаются 2 сеанса?