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!

8
  • 3
    what problems are you having? Commented Jun 19, 2013 at 5:12
  • i am not really shure if relative paths in url will work Commented Jun 19, 2013 at 5:14
  • I cant seem to pass the values field, newValue, firstName and last name to my PHP file Commented Jun 19, 2013 at 5:14
  • have you tried debugging your code? so what exactly is the problem? here's a similar post. stackoverflow.com/questions/4218063/… Commented Jun 19, 2013 at 5:15
  • Yaar....show us the array Commented Jun 19, 2013 at 5:15

2 Answers 2

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']; 
Sign up to request clarification or add additional context in comments.

Comments

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?

1 Comment

Dude, that's the Update DB Script. Moreover, using short codes are not good.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.