mmm2893 mmm2893 - 11 months ago 39
JSON Question

Trying to Convert HTML form into JSON but returning empty

I've been trying to convert an HTML form into Json. When I submit the form my alert is just returning an empty array. Any help is greatly appreciated!

Here is the form

<form action="" method="post" name="myForm">
Code (xxxx-xxx):<input type="text" name="drugcode" /> <br/>
<p><input type="submit" onClick='submitform()' /></p>

And here is the javascript

<script src=""></script>

<script language ="javascript" type = "text/javascript" >

function submitform() {

var formData = JSON.stringify($("form[name*='myForm']").serializeArray());

type: "POST",
url: "serverUrl",
data: formData,
success: function(){},
dataType: "json",
contentType : "application/json",
processData: false


All that this is returning is:


It now returns:


how would I would I have it return:


$("#myForm") is not going to match the form for you. # specifies an id. You need to match on the name:

$( "form[name='myForm']" )...