-2

try setting my code for send variable from view to controller,but my code is not run and show error

Uncaught ReferenceError: $ is not defined

view

<script type="text/javascript">
  $(document).ready(function() {
    var st = $('#st').val();
    var postdata = { st: st };
    $.ajax({
      type: 'POST',
      url: '<?= base_url();?>task_tickets/tes',
      data: postdata,
      success: function(response) {
        console.log(response);
      }
    });
  });
</script>

controller

function cek(){
     echo $st;
}
barbsan
  • 3,418
  • 11
  • 21
  • 28
mido
  • 1
  • 2

1 Answers1

0

Looks like either you have not included jQuery plugin or added after your JavaScript code. $ is alias to jQuery. In your view before script tag, include this

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.js"></script>

Zaid Afzal
  • 362
  • 2
  • 7