I have more than one problem. First one:
How can I send more than one data including JS functions:
$.ajax({
type: 'POST',
url: 'save.php',
cache: false,
data: {
bla: navigator.appVersion,
blah: navigator.platform
}
});
Second problem is connected with first one:
How can I save more than one data:
<?php
foreach($_POST['data'] as $data) {
$bla = $data['data1'];
$blah = $data['data2'];
$file = "test.txt";
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, $bla, $blah);
fclose($fh);
}
?>
Use $_POST['bla'];
and $_POST['blah'];
as your post variables.
You can use jQuery.param which serializes your objects/arrays.
var data = {
object1: {version: navigator.appVersion},
object2: {platform: navigator.platform},
array1: ['one', 'two', 'three']
};
$.ajax({
type: 'POST',
url: 'save.php',
cache: false,
data: jQuery.param(data),
});
and you can see the data structure in php and parse acordingly:
<?php
print_r($_POST);
?>
Marhaba ! Assuming that you have just two input fields in your form you want post so what you need is just this type of code :
<?php
$tobewritten = "";
foreach($_POST as $data)
{
$tobewritten.= $data . ",";
}
$tobewritten = substr($tobewritten,0,strlen($tobewritten)-1);
$file = "test.txt";
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh,$tobewritten);
fclose($fh);
?>
Please 5alline a3ref if this code has helped you and has been the right solution for your problem :)