Skip to content Skip to sidebar Skip to footer

Sending Data With Ajax

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: {

Solution 1:

Use $_POST['bla']; and $_POST['blah']; as your post variables.

Solution 2:

You can use jQuery.param which serializes your objects/arrays.

vardata = {
   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);
?>

Solution 3:

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($_POSTas$data)
{
    $tobewritten.= $data . ",";
}
$tobewritten = substr($tobewritten,0,strlen($tobewritten)-1);

$file = "test.txt"; 
$fh = fopen($file, 'w') ordie("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 :)

Post a Comment for "Sending Data With Ajax"