How to access jQuery serialized data? (ok)

C:\xampp\htdocs\code\index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
  <title>Document</title>
</head>
<body>
  <form id="example_form" action="">
    First name:
    <input type="text" name="FirstName" value="Foo" />
    <br>Last name:
    <input type="text" name="LastName" value="Bar" />
    <br>
  </form>
  <div id="results"></div>
  <script type="text/javascript">
  $(document).ready(function() {
    var $form = $('#example_form');
    var data = $form.serialize();
    console.log(data);
    var fakeURL = "http://localhost/code/index.html?" + data;
    var createURL = new URL(fakeURL);
    console.log(createURL);
    var FirstName = createURL.searchParams.get('FirstName');
    console.log(FirstName);
  });
  </script>
</body>
</html>

Last updated

Navigation

Lionel

@Copyright 2023