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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

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


Go to End


1799 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']"