Raky Sharma Raky Sharma - 1 month ago 11
Ajax Question

Php Ajax difficulty in passing Multiple Data: Parameters.

Here is a code I am working on:-

var finyear = $("#show_finyear").html();
var cmdname = $("#show_commandName").html();
var stnname = $("#show_stationName").html();
var statusname = $("#show_statusList").html();
var cfaname = $("#show_cfaList").html();

$.ajax({

url:"get_value.php",
method:"POST",
data:{var dataArray = finyear + "," + cmdname+ "," + stnname + "," + statusname + "," + cfaname;
}
});


The ajax() code is resulting in error. What is the correct format of sending multiple data variable through data parameter?

Answer Source

There is no need to create an array to send data. Under ajax, send data like this:-

data:{finyear:finyear, 
      cmdname:cmdname,
      stnname:stnname, 
      statusname:statusname,
      cfaname:cfaname
     }  

In get_value.php, the code maybe written like this

    $finyr     = $_POST['finyear'];
    $commdname = $_POST['cmdname'];
    $stationname = $_POST['stnname'];
    $statustype  = $_POST['statusname'];
    $cfanamed    = $_POST['cfaname'];