Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var result = 0;
- var myEvent = function() {
- if (result == 0) {
- document.getElementById('my-button').style.backgroundColor = '#4cff00';
- result = 1;
- } else {
- document.getElementById('my-button').style.backgroundColor = '#6b7077';
- result = 0;
- }
- {
- var xmlhttp;
- if (window.XMLHttpRequest)
- {
- xmlhttp = new XMLHttpRequest();
- var n_JSON = JSON.parse(xmlhttp.responseText);
- var ID = n_JSON.ID;
- var result = n_JSON.result1;
- }
- if (ID == 1 && result == 0)
- {
- var xhr = new XMLHttpRequest();
- xhr.open('POST', "con_data_ajax/work-ajax-data.php?user-work="+user+,true);
- let body = 'result=' + result;
- xhr.send(body);
- if (xhr.status == 200) {
- document.getElementById('result').innerHTML = result;
- }
- }
- #my-button {
- background-color: #6b7077;
- }
- <button id="my-button" onclick="myEvent()">в работе</button>
- <div id="result">0</div>
- $answer = '{"ID":"0", "Name":"xxx"}';
- if(($_POST['login']=="tech_user") AND ($_POST['pass']=="111")){
- $answer = '{"ID":"1", "Name":"Копыча"}';
- }
- if (($_POST['ID']=="1")) {
- $answer = '{"result":"1"}' ;
- OR
- $answer = '{"result":"0"}' ;
- }
- var button = document.getElementById('my-button');
- button.addEventListener( "click" , function(ev){
- if (ev.target.dataset.userId === '1'){
- this.style.backgroundColor = '#4cff00'
- //Получаем данные по юзеру
- var userId = ev.target.dataset.userId;
- var userName = ev.target.dataset.userName;
- // формируем тело на отправку
- var json = JSON.stringify({
- id: userId,
- surname: userName
- });
- //Формируете запрос согласно того как у вас настроен сервер.
- // var xhr = new XMLHttpRequest();
- // xhr.open(.....)
- // xhr.send(json)
- }else {
- this.style.backgroundColor = '#6b7077'
- }
- ev.target.dataset.userId = 0;
- });
Add Comment
Please, Sign In to add comment