Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Form serialize to JSON

function onSubmit( form ){
  var data = JSON.stringify( $(form).serializeArray() ); //  <-----------

  console.log( data );
  return false; //don't submit
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form onsubmit='return onSubmit(this)'>
  <input name='user' placeholder='user'><br>
  <input name='password' type='password' placeholder='password'><br>
  <button type='submit'>Try</button>
</form>
Comment

serialize object to json

Product product = new Product();
product.ExpiryDate = new DateTime(2008, 12, 28);

JsonSerializer serializer = new JsonSerializer();
serializer.Converters.Add(new JavaScriptDateTimeConverter());
serializer.NullValueHandling = NullValueHandling.Ignore;

using (StreamWriter sw = new StreamWriter(@"c:json.txt"))
using (JsonWriter writer = new JsonTextWriter(sw))
{
    serializer.Serialize(writer, product);
    // {"ExpiryDate":new Date(1230375600000),"Price":0}
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: node.js http request ip address 
Javascript :: jquery modal on show + target button 
Javascript :: flatlist footer react native 
Javascript :: jQuery get values of selected checkboxes 
Javascript :: js separate number with comma 
Javascript :: jquery on change function not working 
Javascript :: regex to check if string contains special characters javascript 
Javascript :: regex replace cpf 
Javascript :: Codewars Returning Strings 
Javascript :: wordpress add jquery script 
Javascript :: p5js class 
Javascript :: make page refresh on top in react js 
Javascript :: jquery if attribute 
Javascript :: check if character is a letter 
Javascript :: javascript stringify an object 
Javascript :: exit program js 
Javascript :: why my bootstrap classes is not working on onclick event in react 
Javascript :: com.fasterxml.jackson.databind.exc.unrecognizedpropertyexception unrecognized field 
Javascript :: angular 9 how to get previous state 
Javascript :: brackets not autocompleting in js file in vscode 
Javascript :: edit onclick event 
Javascript :: js upload json 
Javascript :: lip. dips *dipped. also mm bpi. -opp. -ditty 
Javascript :: electron communicate between main and renderer 
Javascript :: get window resolution javascript 
Javascript :: regex all starting with 
Javascript :: javascript regex replace all 
Javascript :: get screen width javascript 
Javascript :: javascript search in object array 
Javascript :: orthographic camera three js 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =