How to make http get JQuery

Hy I'm new to JQuery. I want to send data to http, but I don't know how to send data when using a class. This is my html

<div class="action-lock">
  <div class="toggle-pane">
    <div class='unique' id='switch'>
      <div class='toggle-text-off'>Unlocked</div>
      <div class='glow-comp'></div>
      <div class='toggle-button'></div>
      <div class='toggle-text-on'>Locked</div>
    </div>
  </div>
</div>

      

And this is my JQuery

$('.unique').click(function(e) {
  e.preventDefault();
  $(this).toggleClass('toggle-on');
});

      

How to send http get to Locked

and Unlocked

. For example, example URL localhost/web.php?tN=locked

or localhost/web.php?tN=unlocked

. Please help me to find out how to send http get if so. Thanks to

+3


source to share


1 answer


Try using $. get () like,



$('.unique').click(function (e) {
   e.preventDefault();
   $(this).toggleClass('toggle-on');
   // pass unlocked if it has class toggle-on, otherwise pass locked
   var data = {tN:($(this).hasClass('toggle-on')?'unlocked':'locked')};
   $.get('http://localhost/web.php',data,function(response){
      console.log(response);
   });
});

      

+2


source







All Articles