This commit is contained in:
Aleksandr Shelkovin 2025-01-24 21:01:12 +03:00
parent 0b4a887e7b
commit 2383f9d4f6
3 changed files with 81 additions and 0 deletions

63
AXIOS/index.php Normal file
View File

@ -0,0 +1,63 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<title>MP3 Music</title>
</head>
<body>
<div id="container"></div>
<h1>Подгрузка записей</h1>
<button onclick="getFeedMusic()">getFeedMusic</button>
<button onclick="getJsonMusic()">getJsonMusic</button>
<button onclick="getFetch()">getFetch</button>
<script>
// const axios = require('axios');
let cnt = document.getElementById('container');
// Make a request for a user with a given ID
function getFeedMusic() {
axios.get('./music_html.php')
.then(function(response) {
// handle success
cnt.innerHTML = cnt.innerHTML + response.data;
})
.catch(function(error) {
// handle error
alert(error)
})
.finally(function() {
// always executed
});
};
function getJsonMusic() {
axios({
method: 'get',
url: './music_json.php',
responseType: 'application/json'
})
.then(function(response) {
console.log(response.data);
});
}
async function getFetch() {
const response = await fetch('./music_json.php', {
method: 'get',
})
// .then(function(response){
// let prom = response.json()
let data = await response.json();
console.log(data)
// });
}
</script>
</body>
</html>

8
AXIOS/music_html.php Normal file
View File

@ -0,0 +1,8 @@
<?php
echo <<<'HTML_END'
<audio controls>
<source src="music.mp3" type="audio/mpeg">
<source src="music.ogg" type="audio/ogg">
</audio>
HTML_END;

10
AXIOS/music_json.php Normal file
View File

@ -0,0 +1,10 @@
<?php
$feed = array(["src" => ["music.mp3", "music.ogg"]],
["type" => ["audio/mpeg", "audio/mpeg"]],
["src" => ["music1.mp3", "music1.ogg"]],
["type" => ["audio/mpeg", "audio/mpeg"]]);
header('Content-Type: application/json; charset=utf-8');
echo json_encode($feed);