0

Javascript. POST request. It is not an API request (axios or fetch), but the old classical request.

I need a payload like ...&_selected_action=5&_selected_action=10. So I think I cannot use a form submitting technique here. With a single occurence ...&_selected_action=5 I am able to do it (form submitting as Aquajet @ pass post data with window.location.href), everything works well. For the repeated value I can create the string by hand or by URLSearchParams().toString() but I am not able to send it.

Any idea?

More details. I need create this request in Django+Vue application which partially replaces the old school Django Admin. The ListView is replaced using Vue and now I want to reuse the actions where Django Admin uses Post request formatted as above. So with single selected row in list I am able to do it, but with 2+ selected rows I cannot find a good way how to do it.

mirek
  • 1,140
  • 11
  • 10

1 Answers1

0

In my question above I am not true that I cannot use form submitting method. Of course, html form can have more fields with identical name= and if so, its submit generates a post request exactly as needed.

But while I create the form programmatically, I cannot fill it from dictionary, because dictionary cannot have repeated keys.

So I have modified the function proposed by Aquajet here pass post data with window.location.href and I check if params[key].constructor !== Array. I convert non-array values to array (with single element) and I cycle through such arrays. This allows me to have repeated values in the parameter (in such case I enter them as an array) and in the form.

So, this is answer to my problem. However it is a little strange to create lot of hidden inputs for such goal. So I am interested if there is a better way how to create the POST request.

mirek
  • 1,140
  • 11
  • 10