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'];
}
passing 2 variables from jquery to php file
Moderator: General Moderators
Re: passing 2 variables from jquery to php file
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.
Re: passing 2 variables from jquery to php file
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()}, /
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()}, /