php -ajax function not sending data to controller

Related searches

Ajax function: I can get id in ajax but not able to send to controller. Controller is calling but im not getting data in controller.

function select_report()
     {
      var re_id =  $('#report_id').val();
          // ajax adding data to database
          alert(re_id);
         $.ajax({
            url : "<?php echo site_url('Homepage/category/');?>",
            type: "POST",
            data: {'re_id':re_id},
           success: function(data)
           {
              window.location.href = "<?php echo site_url('Homepage/category/'); ?>";
           },
           error: function (jqXHR, textStatus, errorThrown)
           {
              alert('Error');
           }
       });
     }

Controller Function:

public function category()
    {
        $this->load->model('main_model');
        $this->load->library('session');
        $this->load->helper('url');
        $re_id=$this->input->post('re_id');
        print_r($re_id);
        print_r("Welcome");
        exit();
        $data['report']=$this->main_model->select_report($re_id);
        //Code to load header&footer
        $this->load->view('templates/header');
        $this->load->view('category.php',$data);
        $this->load->view('templates/footer');
    }

Try and check.

function select_report()
{
     var re_id =  $('#report_id').val();
     $.ajax({
        url: '<?php echo base_url();?>Homepage/category/',
        async: false,
        type: 'POST',
        data: {re_id : re_id},
        dataType: 'html',
        success: function(data) {
           console.log(data);
         }
   });

}

Hope this works for you.

Laravel Form not Passing Data to Controller, Use Request (Illuminate\Http\Request) object. Laravel provide Request class and a set of method to handle the request data. For details you� I need to send data via JS to a Laravel controller on a button click. I'm not using any form because the data is being created dynamically. Every time i try to send the data, i get an Internal Ser


We can not load view in ajax request. For that, we have used another method

 function select_report()
    {
      var re_id =  $('#report_id').val();
      // ajax adding data to database
      alert(re_id);
       $.ajax({
          url : "<?php echo site_url('homepage/category/');?>",
          type: "POST",
          data: {'re_id':re_id},
          dataType: 'json',
           success: function(data)
           {
              console.log(data);
              if(data==true){
                window.location.href = "<?php echo site_url('homepage/category_demo/'); ?>"+re_id;
              }else{
                alert('Error');
              }
           },
           error: function (jqXHR, textStatus, errorThrown)
           {
              alert('Error');
           }
      });
    }

In controller

public function category()
    {
        $this->load->library('session');
        $this->load->helper('url');
        $re_id=$this->input->post('re_id');
        $report=$this->main_model->select_report($re_id);
        if(count($report)>0){
            echo json_encode(true);
        }else{
            echo json_encode(false);
        }       

    }
    public function category_demo($re_id){
        $data['report']=$this->main_model->select_report($re_id);
        $this->load->view('templates/header');
        $this->load->view('category.php',$data);
        $this->load->view('templates/footer');
    }

Sending Data To and From a Controller into the Page View, Sending Data To and From a Controller into the Page View Parameters are just passed as additional PHP function parameters, separated by commas. If there's no view_album() method in the media controller, or there is but it doesn't have� I am using ajax to post data to the controller and I need to update the record based on the id I pass through. How would I go about this with Laravel Eloquent


If you use Chrome browser, please check on tab Network and check what header data send to server. Is that have the data you want to send to your controller, and check what is the response from that URL. Please check the response HTTP status also.

And then check on your server side, make sure the the URL can go to your controller. You can die('Test') in you method code to make sure that request touch to your code.

I think the problem come from your URL.

Variables From External Sources - Manual, Example #2 Accessing data from a simple POST HTML form WATCH OUT: these methods ARE NOT supported anymore. You may, for example, group related variables together, or use this feature to retrieve values from a The experienced may note that the actual variable names sent by the browser contains a period� data; success; The type is the way we send out data to the php file. If we use POST then in the PHP file, we use $_POST[”] to get the value. If we use GET then we use $_GET[] The URL is basically the file we want to send the data to. In our case it’s process.php. The data store our data. in our case, text1: val1.


PHP and HTML - Manual, Upon submitting, either via GET or POST, the data will be urlencoded by the browser for So even if your URL is not dynamic, you need to htmlspecialchars() the URL. The solution is to use PHP's "array from form element" feature. which (possibly) can contain arbitrary characters, including control codes ( newline, tab. POST call to Controller's Method to save TextBox data (not form) There are various ways to POST form data to a method but in the example given below I'm not going to use any form. I will just use two textboxes and a submit button, when the user clicks the button I want to save the data using a jQuery Ajax POST call.


Passing by Reference - Manual, Extensions � Non-Text MIME Output � Process Control Extensions � Other Basic Extensions � Other You can pass a variable by reference to a function so the function can modify the variable. Note: There is no reference sign on a function call - only on function definitions. do_sort($data); // does not affect value of $ data I'm trying to send data from a form with ajax to the controller. The Ajax is executing but the function in controller not. I do not get any error, I just get the YES! printed but after that nothing happen.


Code looks fine from what I can tell, no obvious problems. Can you use Firebug or something to inspect the request and make sure the POST data is all there and it’s posting to the correct address? Check the return data of the request too, and maybe test the request with cURL.