12345678910111213141516171819202122232425262728293031 |
- const jsonPost = async (url, data) => {
- try {
- const response = await fetch(url, {
- method: 'POST',
- body: JSON.stringify(data)
- });
- if (!response.ok) {
- new Error(`An error has occurred: ${response.status}`);
- } else {
- return JSON.parse(await response.text());
- }
- } catch (e) {
- return e;
- }
- }
- const url = "http://students.a-level.com.ua:10012";
- sendButton.addEventListener('click', async () => {
- let nickValue = nickInput.value;
- let messageValue = messageInput.value;
- const newPost = await jsonPost(url, {
- func: 'addMessage',
- nick: nickValue,
- message: messageValue
- }
- );
- console.log(newPost.nextMessageId);
- });
|