This might be a bug in the handling of the multipart/form-data content type. Does this still fail if you try to use application/x-www-form-urlencoded as the contentType?

By on 2/14/2017 7:24 AM ()

After further investigation, I figured why it didn't work.

The problem is that the AjaxSettings.ContentType accepts a string option but in order to submit a form-data via ajax, it needs to be set to false (bool typed).

I've tried two things:

  • setting the ContentType to "false" but it simply sends the POST request with content-type="false"
  • setting the ContentType toNone but it simply doesn't include it and therefore the content type becomes the default application/x-www-form-urlencoded

I can see from the JQuery definition: "contentType", (T<string> + T<bool>) but I don't seem to be able to set the content type to false.

So I guess my question changed to - How can I set the AjaxSettings.ContentType to false in order to have the correct content type multipart/form-data; boundary=XXXXX set in the POST request?

By on 2/15/2017 9:15 AM ()

Ha, interesting timing: we actually just fixed this and haven't published it yet :) This is the version currently on NuGet, and it is only T<string>. So the next version of WebSharper 4 will have this parameter as Choice<string, bool>. To get this working right now, you can simply use As<string> false.

By on 2/15/2017 9:22 AM ()

Nice, thanks Loïc, I was setting it with settings?contentType <- false but As<string> false works too.

By on 2/15/2017 9:26 AM ()

Hi Loïc, application/x-www-form-urlencoded works via Ajax post and string data Something=hello.

In my case, I will need to append a file to the form-data together with more input fields. Therefore I was hoping to be able to get the content deserialised into the record type and extract the file from the context request.

Is it possible to have access to the form data from the context?

By on 2/14/2017 9:10 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper