There's no code to send data to the bott telegram. JS
-
var chatid = "id (вырезан)"; var token = "токен (вырезан)"; var name = document.getElementById('user-name'); var contact = document.getElementById('user-contact'); var message = document.getElementById('message'); var text = "text"; var btn = document.getElementById('btn'); btn.onclick { var z=$.ajax({ type: "POST", url: "https://api.telegram.org/bot"+token+"/sendMessage?chat_id="+chatid, data: "&parse_mode=HTML&text="+encodeURIComponent(text), }); };
-
You need to change.
btn.onclick { ... }
♪btn.onclick = function(){ ... }
And then it'll be like,const chatid = '1463152388'; const token = '2036441771:AAHff9GfBVo6QSQeBci7qV2lPFBImamcYpA'; const btn = document.getElementById('btn'); const pre = document.getElementById('console'); btn.onclick = function (){ const text = 'text'; $.ajax({ type: 'POST', url: `https://api.telegram.org/bot${token}/sendMessage?chat_id=${chatid}`, data: 'parse_mode=HTML&text=' + encodeURIComponent(text), }) .done((data) => pre.innerHTML = JSON.stringify(data, null, 2)) .fail((err) => console.error('error', err)); };
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <button id="btn">Отправить тестовое сообщение</button> <pre id="console"></pre>