S
S
Sergey Zolotarev2020-11-21 19:36:42
JavaScript
Sergey Zolotarev, 2020-11-21 19:36:42

How to convert serialized string to JSON in JavaScript and jQuery?

Good evening!

Are there better options for converting a string returned by a jQuery method serialize()to a JSON string using JSON.Stringify()?


Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-11-21
@seregazolotaryow64

Have you even tried googling yourself? Well, it's 3 seconds.

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

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

<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>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question