I send a request to the server as follows

$.ajax({ type: "POST", url: "/words", data:{ ..., 'translations':$('#select-translation').val() }, ... }); 

The translations field is an array (at least the server is expecting an array). $('#select-translation').val() returns an array ( ["1571", "1895"] ) but when sent, the parameter name changes to translations[] and naturally does not reach. Actually the question is: how to send an array correctly?

  • one
    'translations':$('#select-translation').val().join(",") - Igor
  • @Igor Thank you very much, issue as an answer, I will mark as true! - JVic
  • Glad to help fellow Krivorozhanin. - Igor
  • @Igor Well, wow!))) The world is too small and stackoverflow and for a long time)) - JVic
  • My women-grandfathers lived on Sivolapa and Rosa Luxemburg. It seems both streets are now renamed. - Igor

2 answers 2

As an option:

 'translations':$('#select-translation').val().join(",") 

taking into account that you are on the server side.

    There is another option to send data like this:

     dataType: 'json', data:{ ..., /*без ковычек, ибо это объект*/translations:$('#select-translation').val() }, 

    here is my working code for this topic:

     $("#add_result").html("Добавляем..."); $.ajax({ url: "/device/add", data: { name: "device", nomer: "123456", imei: "123456789012345" }, type: "POST", dataType: 'json', success: function(json) { /*******/ $("#add_result").html(json.txt); }, error: function(x, t, m) { /*******/ $("#add_result").html("<option color='red'>Невозможно добавить устройство</option>"); } })