Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

[solved] jquery.ajax question (retrieving data values on )


Go to End
Reply


483 Views

Avatar
Bimble

Community Member, 16 Posts

8 January 2014 at 10:59pm

Edited: 08/01/2014 11:04pm

How do I pull out the ajax data from the Controller action?

The documentation "autocomplete" example seems to suggest using $request->getVar('varname'), but that's not working for me...

javascript

(function($) {
    $(document).ready(function(){
        kpi_data_request(1);
    })
})(jQuery);

function kpi_data_request(id) {
   jQuery.ajax({
      type: "POST",
      url: "/ChartKPI_Contoller/send_data",
      data: {
        "js": true,
        "id": id,
      },
      dataType: "json",
      success: function (dataseries) {
        {alert(dataseries)}
      },
      error: function (xmlhttp) {
        {alert('bad')}
      },
    });
}

Conroller

public function send_data($request) {
     $id = $_REQUEST['id'];
     return json_encode("id:".$id);
   }

Solution: I must have been sleeping: "$id = $_REQUEST['id']"