Here it is a fragment of my code:

$.ajax({ url: 'ajax/ajax.feedback.php', type: 'POST', data: 'author=' + author + '&mail=' + mail + '&subject=' + subject + '&text=' + text + '&checkbox[1]=' + checkbox[1] + '&checkbox[2]=' + checkbox[2] + '&checkbox[3]=' + checkbox[3] + '&checkbox[4]=' + checkbox[4] + '&checkbox[5]=' + checkbox[5] + '&checkbox[6]=' + checkbox[6] + '&checkbox[7]=' + checkbox[7] + '&checkbox[8]=' + checkbox[8] + '&checkbox[9]=' + checkbox[9], success: ... 

How to make it easier? Just send an array? (and how to read it later in php? If there are any features) In Google - it’s not clear - you need to create an object like, use json. In practice, nothing comes of it.

    3 answers 3

    http://api.jquery.com/jQuery.post/

    there is an example

     $.post("test.php", { 'choices[]': ["Jon", "Susan"] }); 

    for your case there should be something like this:

     $.post('ajax/ajax.feedback.php', {'author':author,'mail':mail,'subject':subject,'text':text,'checkbox[]':checkbox}, function (html) { success ... }); 

    and even easier, you can:

     $.post("test.php", $("#testform").serialize()); 

    on the server, the whole thing will be in the $ _POST array; just print it on print_r screen ($ _ POST) and everything will become clear

    • He started with the first option - it's pretty simple. Thank! - Rasim Bayturin

    Here is an example using JSON:

     var author = document.getElementById("author").value; ... $.ajax({ url: 'ajax/ajax.feedback.php', type: 'POST', data: ({author:author, id:id, mail:mail}), success: function(data) {} }); 

    data is received through the $ _POST array

      As always, there are options:
      1. Merge everything into a string with a separator (in the string, change all entries of the delimiter to html equivalents) and send all with one parameter. And on the server, do explode (); .
      2. Read here - http://www.simplecoding.org/otpravka-dannyx-v-formate-json-s-pomoshhyu-javascript-i-jquery.html . It seems like everything is available written.
      In principle, the methods are similar.