2

I have a textarea:

<textarea cols="20" id="testtextbox" name="testtextbox" rows="2">test</textarea>

and I POST it by building a FormData object:

var newForm = $('<form></form>').append($("#testtextbox"))
var formdata = new FormData(newForm.get(0));

var xhr = new XMLHttpRequest();
xhr.open('POST', '/', true);
xhr.send(formdata);

JSFiddle here

I would expect this to post the value of that one textarea, which works on Chrome and Firefox. However, on Edge 42.17134 the POSTed request body is:

-----------------------------7e2203930476
Content-Disposition: form-data; name="testtextbox"
 
 
-----------------------------7e2203930476--

This also works fine in previous versions of Edge. Am I doing something wrong? As far as I can tell I'm not relying on any deprecated features.

Community
  • 1
  • 1
Thomas Boby
  • 778
  • 8
  • 22

1 Answers1

1

According to your description and code, I suggest that you could check the official API about formdata and modify your code like the following two ways.

1.use formdata.append to post the value

<textarea cols="20" id="testtextbox" name="testtextbox" rows="2">test</textarea>
<script type="text/javascript">
   var formdata = new FormData();
   formdata.append("testtextbox", testtextbox.value);
   var xhr = new XMLHttpRequest();
   xhr.open('POST', '/', true);
   xhr.send(formdata);
</script>

the result:the first way

2.add a form to the page body

<form id="form1" name="form1">
    <textarea cols="20" id="testtextbox" name="testtextbox" rows="2">test</textarea>
</form>
<script type="text/javascript">
    $(function () {
        var newForm = $("#form1");
        var formdata = new FormData(newForm.get(0)); 

        var xhr = new XMLHttpRequest();
        xhr.open('POST', '/', true);
        xhr.send(formdata);
    })
</script>

the result:the second way

Best Regards,

Jenifer

Jenifer Jiang
  • 371
  • 1
  • 9
  • The problem with 1 is that I need the browser's intelligent parsing of inputs. And I can't just add a form element to the body because I'm collecting several inputs from across the whole page. – Thomas Boby Oct 12 '18 at 16:01
  • I've tested in several browsers and I do see that Edge may lose the value. I think the code is not wrong.In my opinion, it is specific in Edge that maybe just the version "hide" the value or it is a small bug. – Jenifer Jiang Nov 14 '18 at 10:00