I have a PHP file contain some calculation. Now, I want to integrate the calculation into javascript in another file. How i can pass the variable in javascript to do calculation inside php?
this is my javascript code:
$("#upload").on("click", function(){
var csv = $('#csv');
var csvFile = csv[0].files[0];
var ext = csv.val().split(".").pop().toLowerCase();
if($.inArray(ext, ["csv"]) === -1){
alert('upload csv');
return false;
}
if(csvFile != undefined){
reader = new FileReader();
reader.onload = function(e){
csvResult = e.target.result.split(/\r|\n|\r\n/);
var temp=[];
for(i=0;i< csvResult.length; i++){
if(csvResult[i] != "" && csvResult[i] != null){
var data = csvResult[i].split(",");
var rssi = data[0];
var distance = data[1];
var rssisample = 8;
if(distance == 1){
//need to insert calculation method from php
temp.push(rssi);
}
}
}
I have php file name myphpfile.php. So, I want to use variable and value from javascript to perform calculation in php file and return back to javascript. Please help me on this
This is my some part of php file. eg: myphpfile.php
<?php
// $arrTimeRSSI will read from javascript before perform this calculation
//calculate mean X using array_sum() method
$avgRSSI = array_sum($arrTimeRSSI)/($num_of_elements);
function StandardDeviation($arrTimeRSSI){
global $num_of_elements;
global $avgRSSI;
$variance = 0.0;
foreach($arrTimeRSSI as $x){
//sum of squares of difference between all numbers and mean X
$variance += pow(($x - $avgRSSI), 2);
}
$newElements = $num_of_elements - 1;
return (float)sqrt($variance/$newElements);
} ?>