开发者

Is it possible to post data to an html form without it being in a key-value collection?

开发者 https://www.devze.com 2023-03-07 15:40 出处:网络
I am wondering if it is possible 开发者_C百科to post data without using the standard form\'s key-value pair collection. I\'d like to just send my data without having to deal with the HTML form\'s dict

I am wondering if it is possible 开发者_C百科to post data without using the standard form's key-value pair collection. I'd like to just send my data without having to deal with the HTML form's dictionary of data.

Is this possible using JavaScript or any other means?

I am using ASP.NET MVC, but I don't believe this makes a difference for this question.


Sure. Imagine posting with XHR.

With XHR, there is no HTML Form Encoding to deal with. That is, with XHR, one can post whatever data is desired (such as some JSON, a base64 encoding of an image, or even a simulated form encoding) and it won't be framed as with a normal form submission. The most simple (and "raw") way of processing XHR requests (in ASP.NET) is to use PageMethods, see links.

Going through the "form submit" route requires the browser to abide by the HTML Form Encoding (think of the poor back-end and how confused it would get!) as this is "just how HTML works" on a submit. It would be possible to shove all the data to send (after serialization) into a hidden field (which would still honor HTML Form Encoding), but this really sounds like an X-Y question. (That is, if the form collection isn't easy to deal with -- why not? In ASP.NET, using Controls will hide the details).

Happy coding.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号