R
R
rusgayfer2018-02-13 23:39:19
JavaScript
rusgayfer, 2018-02-13 23:39:19

How to make button update after ajax click?

So that when you click on the enable button, it immediately changes to disable

<button type="button" class="btn btn-success" id="zadaniya_off" name="zadaniya_off">Отключить</button>
<button type="button" class="btn btn-success" id="zadaniya" name="zadaniya">Включить</button>

$("#zadaniya_off").on('click', function() {
    var zadaniya_off = $("#zadaniya_off").val();
    var data = {
        'zadaniya_off': $("#zadaniya_off").val(),
    };
    $.ajax({
      url:"/personal", 
      data:data, 
      type:'POST', 
      dataType: 'json',
      success:function(data){
        if( data.code == 0 ) {
          $('#okey').html('<div class="callout callout-success">Успешно выключено.</div>');
        }
      }
    });

  });
  
  $("#zadaniya").on('click', function() {
    var zadaniya = $("#zadaniya").val();
    var data = {
      		'zadaniya': $("#zadaniya").val(),
    };
    $.ajax({
      url:"/personal", 
      data:data, 
      type:'POST', 
      dataType: 'json',
      success:function(data){
        if( data.code == 1 ) {
          $('#okey').html('<div class="callout callout-success">Успешно включено.</div>');
        }
      }
    });

  });

We display the text with a successful enable/disable I send the codes like this:
<div id="okey"></div>
$answer = [
    'code' => '1',
  ];
  echo(json_encode($answer));
  die();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Kit, 2018-02-14
@ShadowOfCasper

With ajax - will not work on the field - you need a server
https://jsfiddle.net/cajhu3ds/14/

R
rusgayfer, 2018-02-14
@rusgayfer

None of the suggested ones work or fit.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question