2

I have some code:

var formData = new FormData(eForm);
var xhr=GetXMLHttpRequest();
xhr.open('POST', surlAjax,false); 
xhr.send(formData); 

When I view the request payload in chrome I see:

Request Payload

------WebKitFormBoundary2Sol1RjAh9VTx3uj Content-Disposition: form-data; name="answer"

1 ------WebKitFormBoundary2Sol1RjAh9VTx3uj Content-Disposition: form-data; name="idSlide"

11 ------WebKitFormBoundary2Sol1RjAh9VTx3uj Content-Disposition: form-data; name="sEnduser"

ceff69eabdcd494de62b110c0c7231aa ------WebKitFormBoundary2Sol1RjAh9VTx3uj--

When I view the request Payload in Safari I see:

Request Payload

------WebKitFormBoundary3rBEoL5qcra4nVCd--

The eForm object is an HTMLFormElement object which is required by the constructor of FormData.

Any ideas why the request payload would be different in safari vs chrome?

hellopat
  • 1,799
  • 2
  • 14
  • 14

1 Answers1

3

I've reproduced it on 5.0.5 here... looks like it's a problem with the FormData constructor - it doesn't add all the values in the form, but .append() works just fine.

Steve
  • 49
  • 3
  • Thanks Steve. I did actually end up figuring out that it was a browser issue. I rewrote the function to support the submission using .append(). – hellopat Jun 15 '11 at 16:46
  • It should support it though - it is meant to be able to take a form as a constructor argument, and the latest webkit does have a test that checks it works. I guess v5 is just too old and we'll have to wait for v6 for Safari to support it correctly. – Steve Jun 15 '11 at 17:16
  • 1
    For anyone who finds this thread, Safari 5.1.7 handles passing a form into `new FormData()` just fine. One thing that confused me was that you can't access the formData object's properties directly. You need to send the formData first then you can see what properties were passed either in your receiving service or by using the network tab. This is standard for all browsers as far as I'm aware. – Chad von Nau Jan 11 '13 at 02:13
  • Following on from @ChadvonNau's comment, here's a thread that actually gives a useful explanation of how you can view formdata properties: http://stackoverflow.com/questions/7752188/formdata-appendkey-value-is-not-working – StackExchange What The Heck Dec 29 '14 at 15:52