1

AJAX codes

$.ajax({
    type: "POST",
    url: "../updateDB.php",
    data: {
        field: idValue[0],
        newValue: newValues,
        firstName: idValue[2],
        lastName: idValue[3]
    },
    success: function(){

    }  
});

PHP File (updateDB.php)

$field = $_POST['field'];
$newValue = $_POST['newValue'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];

I want to pass the values from my JQUERY file to my PHP file. HELP!! Thank you!

Vivek Jain
  • 3,811
  • 6
  • 30
  • 47
tine
  • 11
  • 6

2 Answers2

1

Try something like:

   $.post( 'updateDB.php',
   {
       'field'         : idValue[0],
       'newValue'      : newValues,
       'firstName'     : idValue[2],
       'lastName'      : idValue[3]
   },
   function( data )
   {
       $('#response').html( data );
   });

Include the following on your page (to show the server response):

   <div id="response"></div>

Then put the following into your PHP script to dump the posted values right back to the web page (to give you a visual queue that things are working):

   echo "<pre>" . print_r( $_REQUEST, true ) . "</pre>";

You can access the individual values using

   $field  = $_REQUEST['field'];
   $newVal = $_REQUEST['newValue']; 
Kevin Traas
  • 415
  • 4
  • 5
0

If you are using Ajax function in PHP file then you can use this way

 data: { 
         field: '<?=$field?>', 
         newValue: '<?=$newValue?>', 
         firstName: '<?=$firstName?>', 
         lastName: '<?=$lastName?>'
       },

let me know is this helpfull?

Rakesh Singh
  • 1,250
  • 9
  • 8