I have a form like this;
<div id="employeeinfo" style="padding:40px" class="employee-body">
<form id="employeeform" title="" method="post">
<label class="title">First Name</label>
<input type="text" id="fname" name="first_name" >
<label class="title">Last Name</label>
<input type="text" id="lname" name="last_name" >
<input type="submit" id="submitButton" onclick="formSubmit()" name="submitButton" value="Submit">
</form>
</div>
I have a json url: “app.employee.com/employeedata”
I need to get fname and lname from html form and search through the json in above url and display it in
so far i have this:
<script type='text/javascript'>
function formSubmit(){
var formData = JSON.stringify($("#employeeform").serializeArray());
$.ajax({
type: "POST",
url: "serverUrl",
data: formData,
success: function(){},
dataType: "json",
contentType : "application/json"
});
}
</script>
How to proceed with this? I’m doing this in shopify.
4
Answers
You can start with use of the getElementById method.
In your case your
serializeArray
only will fetch all the form data and will return likeThen in your back end file you can read the post data.
If you want to get each element value by your own then you need to use:
Then
try this way
The
success function
in yourajax
call returns data from the server:Source: jQuery.ajax docs
So what you can do is: