How to read entire form of POST'ed JSON without parameters into vb.net native object
Account Home | Help | Blog | Contact us | Log Out


Welcome to Kbytes > Articles

How to read entire form of POST'ed JSON without parameters into vb.net native object

Posted By: siteadmin on 30/11/2021 12:56:00

Maintaining javascript clientside and .net serverside classes is a breeze now with Newtonsoft.Json.   But how do you POST up your data from Jquery?
 
If you have a HTML form then using something like https://github.com/marioizquierdo/jquery.serializeJSON is a good idea.  It handles a lot of the nuances of HTML Forms, such as the bonkers way checkboxes are sent.
 
     e.preventDefault(); // avoid to execute the actual submit of the form.
     var formData = $('form').serializeJSON({ checkboxUncheckedValue: "off" });  
     var serialData = "formData=" + encodeURIComponent(JSON.stringify(formData))  
 
     $.ajax({
          type: 'POST',
          data: serialData,
          url: 'hander.ashx?command=ADDARTICLE',
          error: genericError,
             success: function () {
                   window.location.href = '/';
                        }
              });
 
But what if it just normal 'clean' parameters from a function, how can you send a parallel Javascript Class over the wire, and reconstruct it .net server side.
 
 
Dim reader As New System.IO.StreamReader(HttpContext.Current.Request.InputStream)
Dim requestFromPost As String = reader.ReadToEnd()
 
Dim myObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of stripeEvent)(requestFromPost)
 
This looks good!
 
use this to POST up in the Request Body.  https://stackoverflow.com/questions/10110805/jquery-post-json-object-to-a-server/10110924

blog comments powered by Disqus

Kbytes Home | Privacy Policy | Contact us | Testing Area

© 2004 - 2024 1 Oak Hill Grove Surbiton Surrey KT6 6DS Phone: +44(020) 8123 1321