passing 2 variables from jquery to php file

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
bluestar
Forum Newbie
Posts: 13
Joined: Thu Mar 17, 2011 7:19 am

passing 2 variables from jquery to php file

Post by bluestar »

i have syntax problem while transferring more than 2 values from jquery to php file ..but code dint work...when i try to transfer only 1 variable it works but
not with more than 1 variable....here is the codes that im using..

var data1=$("#textbox1").val(); //textbox with name textbox1 in html page
var data2=$("#textbox1").val(); //textbox with name textbox2 in html page
$.ajax({
type: "POST",
url: "insert.php",
data: { data1,data2}, //i stuck in this line
cache: false,
success: function(html){
//some codes here
},
});

in insert.php file:

if(isset($_POST['data1'])||isset($_POST['data2']))
{
echo $_POST['data1'];
echo $_POST['data2'];
}
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: passing 2 variables from jquery to php file

Post by pickle »

You're not setting the names of those variables. You need to do something like:

Code: Select all

{nameOfVariable:data1,nameOfSecondVariable:data2}
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
bluestar
Forum Newbie
Posts: 13
Joined: Thu Mar 17, 2011 7:19 am

Re: passing 2 variables from jquery to php file

Post by bluestar »

dint worked....i also tried
1)var datasent = 'contet='+ test+'&txt1='+test2;
data : datasent,
2)var datasent = 'contet:'+ test+'&txt1:'+test2;
data : datasent,
3)data:{ contet : $("#textbox1").val() , txt1=$("#textbox1").val()}, /
Post Reply