jquery - i want to send data from js to php -


this question has answer here:

i want send data js file php file function receives data , performs further actions on it. problem data isn't receiving js controller function.

js code:

$("#mybtn").click(function(){    $.post(<?= base_url()?>+"upload",{a1: $('#a1').val(), a2:    $('#a2').val(), a3: $('#a3').val(), a4: $('#a4').val(),a5:    $('#a5').val()},function(data) {   });  });      

controller function:

function upload() {    echo "this upload";    $data = array(     'name' => $this->input->post('a1'),     'email' => $this->input->post('a2'),     'pass' => $this->input->post('a3'),     'amnt' => $this->input->post('a4'),     'pcode' => $this->input->post('a5')   );    $result = $this->pages_m->upload($data);    var_dump($data);  } 

first declare on header, after dont need use base_url() function again in ajax.

<script>    var url = <?php echo base_url(); ?> </script>  $("#mybtn").click(function(){  $.ajax({                       url: url+'upload',        type: 'post', // performing post request   data : {      a1: $('#a1').val(),       a2: $('#a2').val(),       a3: $('#a3').val(),       a4: $('#a4').val(),      a5: $('#a5').val()   },   datatype: 'json',                      success: function(data)            {     console.log(data)   }    }); }); 

in controller

function upload()  {    if($_post){      $data = array(      'name' => $this->input->post('a1'),      'email' => $this->input->post('a2'),      'pass' => $this->input->post('a3'),      'amnt' => $this->input->post('a4'),      'pcode' => $this->input->post('a5')      );      $result = $this->pages_m->upload($data);      if($result == true){         echo "successfully save";            }else{         echo "error";      }       }     } 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -