Home > Software design >  How to pass the ajax value to the controller and get the data from db?
How to pass the ajax value to the controller and get the data from db?

Time:12-09

$(document).ready(function() {
    $('#csubmit1').on('click',function (event) {
      // alert("test");
      event.preventDefault();
      var formData = {
      orderfrom1: $("#orderfrom1").val(),
      orderto1: $("#orderto1").val(),
      agentlist1: $("#ag1").val(),
    };
      
        console.log(formData);
        $.ajax({
            type:"POST",
            url:"<?php echo base_url(); ?>home/obwirelessreports",
            data:formData,
 success:function (data) {
                $('#search_change1').html(data);
            }

        });
      
    });
});

Controller.php

$details=$this->input->post();
        
            $data["orderfrom1"]=date("Y-m-d",strtotime($details['order_from']));
            $data["orderto1"]=date("Y-m-d",strtotime($details['order_to']));
            $data["agentlist1"]=$this->Maindata->wiresearch1($details);

Model.php


        $orderfrom=date("Y-m-d",strtotime($data2['order_from']));
        $orderto=date("Y-m-d",strtotime($data2['order_to']));
        $agent_list = implode(', ', array_map(function($val){return sprintf("'%s'", $val);}, $data2["agentlist1"]));

I don't Know how to pass the data from ajax to the controller . Is this the right way ? i have tried using the data in a single array but it is not working . What is the Changes that i should make ?

CodePudding user response:

You're sending the parameters orderfrom

  • Related