javascript - jquery post form and variables together -


i used code send form + variable php-script.

function upload() {   var test = "test";   var infos = $('form').serialize() + '&' + test;   $.post("ajax.php", { infos: infos }).done(function (data) {     alert(data);   }); } 

now php-code:

$data = $_post['infos']; echo $data; 

returns: formfield1=value1&formfield2=value2&formfield3=value3&test

all values in variable... how can use them seperatly php?

for example:

$data = $_post['formfield1']; 

didn't worked :(

use jquery's serializearray(). return array of objects contain 2 properties: name , value. can parse , pass data.

it this

var formdata = = $('form').serializearray(); var infos = { }; (var = 0; < formdata.length; i++) {     infos[formdata[i].name] = formdata[i].value; }  // add separate values, add them `infos` infos.newitem = "new value";  $.post("ajax.php", infos).done(function (data) {     alert(data); }); 

then in php, you'll retrieve values using $_post["formfield1"].


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -