-1

I created a form and serialized its content to JSON. I'm kinda new to json. What i want to do is send the json to a url via POST but i dont know how to go about this. Here's my code

<h1>Register</h1> 
    <form class = "myform"  method="get"> 
        Name:<br /> 
        <input type="text" name="name" value="" /> 
        <br /><br /> 
        Phone Number:<br /> 
        <input type="text" name="telephone" value="" /> 
        <br /><br /> 
        Location:<br />
        <input type = "text" name = "location" value="" />
        <br /><br />
        Logo:<br />
        <input type = "text" name = "logo" value="" />
        <br /><br />
        Website:<br />
        <input type = "text" name = "website" value="" />
        <br /><br />
        Email:<br />
        <input type = "text" name = "email" value="" />
        <br /><br />
        Category:<br />
        <input type = "text" name = "category" value="" />
        <br /><br />
        Postal:<br />
        <input type = "text" name = "postal" value="" />
        <br /><br />
        Description:<br />
        <input type = "text" name = "description" value="" />
        <br /><br />
        GPS:<br />
        <input type = "text" name = "gps" value="" />
        <br /><br />
        Tags:<br />
        <input type = "text" name = "tags" value="" />
        <br /><br />
        Advert:<br />
        <input type = "text" name = "advert" value="" />
        <br /><br />
        Facebook:<br />
        <input type = "text" name = "facebook" value="" />
        <br /><br />
        Twitter:<br />
        <input type = "text" name = "twitter" value="" />
        <br /><br />
        Google:<br />
        <input type = "text" name = "google" value="" />
        <br /><br />
        <input type="submit" value="Submit" /> 
    </form>
        <script src="jquery-1.11.1.min.js"></script>
    <script>
        var frm = $(document.myform);
        var data = JSON.stringify(frm.serializeArray());
        console.log(data);
    </script>

So how am I supposed to go about POSTing it to the url? (assuming the url is www.me.com)

digiwebguy
  • 460
  • 1
  • 8
  • 20
  • 1
    You've got jQuery there, so use [`$.post()`](http://api.jquery.com/jquery.post/)? – Marty Aug 24 '14 at 05:39
  • Did you atleast try a [google search](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=how%20to%20post%20json%20using%20jquery)? Before posting? – T J Aug 24 '14 at 05:53
  • You should try google before posting a question in stackoverflow, its gonna affect your reputation. ;) –  Apr 02 '15 at 23:44

1 Answers1

1

Hi you can use ajax call to send json data

     jQuery.ajax(

     {
              url : getPostData.php,
              type: 'POST',
              dataType : "json",
              data: data,
              success:function(data) { alert(data); },
              error: function() {alert(data); }
     }
   );
Satish Shinde
  • 2,878
  • 1
  • 24
  • 41