Fenixbox has such an example Ajax request:

$.ajax({ type:"POST", cache:false, url: "/data/login.php", data: $(this).serializeArray(), success: function(data) { $.fancybox(data); } }); 

so, how to determine in which variable the array was passed to the server, how to output it in php, namely data: $(this).serializeArray() ?

    2 answers 2

    Indicate explicitly

     $.ajax({ type:"POST", cache:false, url: "/data/login.php", data: {param: $(this).serializeArray()}, success: function(data) { $.fancybox(data); } }); 

    In php, you accept the $ _POST ['param'] variable.

    PS Immediately did not pay attention to one thing - before using $ .ajax (), it is better to drive the entire array into a variable (for example, var someArr = $ (this) .serializeArray () ), since $ (this) in the ajax itself may not be visible.

    • I would say - this can not be seen, rightly noticed. - Zowie
    • and in php how to display it, let's say one pair of key-value array? - Smash
    • something like this: if (! empty ($ _ POST ['param'])) {print_r (unserialize ($ _ POST ['param'])); } - Zowie
    • Yes thank you! - Smash

    As far as I understand, in this example, the data is sent without a form header. And this is exactly what chop causes PHP to parse the values ​​sent by the client into the $_POST global variable. If print_r($_POST); displays an empty array - the way it is. Fortunately, solving this problem is quite simple:

      $cleanPostData = file_get_contents( 'php://input' ); $post = unserialize( $cleanPostData ); print_r( $post ); // и того массив данных 

    Or, as already written above - specify the parameter explicitly, but, in your case, it will not save you from serialization.