PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 1, 2022

[FIXED] How to pass the ajax value to the controller and get the data from db?

 January 01, 2022     ajax, codeigniter, php     No comments   

Issue

$(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 ?


Solution

You're sending the parameters orderfrom𝟏,orderto𝟏,agentlist𝟏 but reading orderfrom,orderto,agentlist, they have to match exactly.

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

I don't know what data2 in the Model but the keys may have to match as well.



Answered By - Musa
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing