What to do with php after jquery.serialize ()

Well, somehow I have the hardest time figuring this out, so I want to make an ajax call with the form and it using jquery to serialize it using .serialize (). The data sent to php looks something like this.

key1=value&key2=value2&key3=value3

And im using a mail request. It looks simple enough, but for some reason it is very difficult for them to figure out how to access these key / value pairs, I can not use explode (), and because it will give me

[0] => key1=value1
[1] => key2=value2
[2] => key3=value3

and I cannot use $ _POST ['key1'] or $ _GET ['key1'] in php to access these values. What should I do!!! Thanks

And as a side question I noticed .serilize () replaces line breaks with% 0A and spaces with +, how can I decode these values ​​with php? Thanks again!

Edit:

, jquery :

var formSubmit = $(this).serialize();
$.post('ajax.php',{"formSubmit": "true", "formInfo": formSubmit}
+3
3

jQuery Ajax, .serialize(). urldecode POST.

. :

HTML

<form id="category-dynamic" class="dynamic">
   <fieldset id="inner-fieldset">
      <legend id="new-category">
        <label for="category-name">Category Name: </label>
        <input type="text" name="category-name" value="" />
      </legend>
      <ul id="category-fields">
         <li>
           <label>Field #1:</label><br />
           <input type="text" name="fields[]" value="" />
         </li>
         <li>
           <label>Field #2:</label><br />
           <input type="text" name="fields[]" value="" />
         </li>
      </ul>
   </fieldset>
</form>
<h3>POST Result</h3>
<pre></pre>

JQuery

$(document).ready(function(){
    $('pre').html($('#category-dynamic').serialize());

    $.post("http://jfcoder.com/test/processor.php", $('#category-dynamic').serialize(), function(data){
         $('pre').html($('pre').html()+"\n\n"+data);
    });
});

processor.php:

<?php
print_r($_POST);
?>

2

, , , , URL-.

, :

var formSubmit = $(this).serialize() + "&formSubmit=true";
$.post('ajax.php', formSubmit);

, POST- .

3

. :

:

$(document).ready(function(){
    var serial = $('#category-dynamic').serialize() + "&formSubmit=true";
    $('pre').html(serial);
    $.post("http://jfcoder.com/test/processor.php", serial, function(data){
         $('pre').html($('pre').html()+"\n\n"+data);
    });
});

"&formSubmit=true" . PHP:

POST Result

category-name=&fields%5B%5D=&fields%5B%5D=&formSubmit=true

Array
(
    [category-name] => 
    [fields] => Array
        (
            [0] => 
            [1] => 
        )

    [formSubmit] => true
)

EDIT 4

, . . ?

$(document).ready(function(){
    var serial = $('#category-dynamic').serialize();
    $('pre').html(serial);
    $.post("http://jfcoder.com/test/processor.php", {"formSubmit":"true","serial":serial}, function(data){
         $('pre').html($('pre').html()+"\n\n"+data);
    });
});

POST Result

category-name=&fields%5B%5D=&fields%5B%5D=

Array
(
    [formSubmit] => true
    [serial] => category-name=&fields%5B%5D=&fields%5B%5D=
)
+6

Values ​​exist in the formInfoindex of the $ _POST array,

print_r( $_POST['formInfo'] );

echo $_POST['formInfo']['key1'];
0
source

All Articles