php - Simulate html form POST using ajax/jquery -


i want read post variables , content form , post them using jquery's "$.post()". first of all, won't job: $.post("myserver.com/test2.php", $('#myform').serialize()) because send 1 variable i'd have parse on php side.

here how i'd start:

function doindirectpost() {     variablewiththeformpostdata = {};     $("#idofmyform :input").each(function() {         variablewiththeformpostdata[$(this).attr("name")] = $(this).attr("value");     }     document.getelementbyid("idofmyform").submit();     $.post("myserver.com/test2.php", variablewiththeformpostdata); } 

and i'd use $.post() post data seperated in multiple variables (just normal form submit it... read somewhere, this:

$.post('myserver.com/test2.php.php',{     var1: content1,     var2: content2 } 

but want dynamic. part:

    var1: content1,     var2: content2 

should autmatically contain variable names , values of form.

in end i'd able post variables this:

foreach ($_post $key => $value) {     echo $key . "= " . $value; } 

serialize doesn't send 1 variable, sends name value pairs of input elements in form.

    $("#idofmyform").on("submit", function () {         $.post("myserver.com/test2.php", $("#idofmyform").serialize(),                  function(datafromserver){                    //server sent response whatever want after form has been submitted                     //or submit form regular way $("#idofmyform").submit();                  }         );         return false;     }); 

should work. remember set name attribute of every input/select element in form.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -