django django - 1 year ago 111
Ajax Question

how to send parameter in ajax call

I have one AJAX call. I need to pass some parameters to my function. This is my AJAX call.

url: 'lib/function.php',
data: {
action: 'getStoreSupplyItems',
id: store_id,
indent: 1
success: function(output) {

Here is my back end function definition that I am trying to call:

function getStoreSupplyItems($category = '')
global $db;
$data = $_REQUEST;
$category = (!empty($category) ? ' AND cim.item_group_code IN ("'.$category.'") ' : '');

if ($data['id'] != "")
$store = $data['id'];
$store = $_SESSION['user']['store']['id'];

How can I pass some arguments to the function? The parameter that I want to pass is something like '12,5,6'.

Answer Source

You can put a switch statement in your php file and then call the function passing the arguments. Like this

  case "getStoreSupplyItems" :

In your getStoreSupplyItems function you can get the value as a param and also use other get params by $_REQUEST or $_GET.

I hope this is what you looking for.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download