How do I correctly append the entire form data to ajax post
hi guys
how do i correctly append form data to an ajax post ?
here is my code below
- <form id="List_Form">
- <div asp-validation-summary="ModelOnly" class="text-danger"></div>
- <div class="form-group">
- <label asp-for="Who_Is_It_For" class="control-label">I want to create a list for:</label>
- @Html.DropDownList("Who_Is_It_For", new List<SelectListItem>
- {
- new SelectListItem{ Text="Myself", Value = "Myself" },
- new SelectListItem{ Text="A Friend", Value = "A Friend" },
- new SelectListItem{ Text="My Group", Value = "My Group" },
- }, new { @class = "btn font-weight-normal" })
- <span asp-validation-for="Who_Is_It_For" class="text-danger"></span>
- </div>
- <div class="form-group">
- <div class="row">
- <div class="col-md-7">
- <label asp-for="ListType" class="control-label"></label>
- <select asp-for="ListID" class="form-control" asp-items="ViewBag.ListID"> </select>
- <span asp-validation-for="ListType" class="text-danger"></span>
- </div>
- <div class="col-md-5">
- or <input type="text" placeholder="Custom List" class="form-control" />
- </div>
- </div>
- <div class="form-group">
- <label asp-for="Privacy" class="control-label">Privacy</label>
- @Html.DropDownList("Who_Is_It_For", new List<SelectListItem>
- {
- new SelectListItem{ Text="Private - (Only me can see it)", Value = "Private" },
- new SelectListItem{ Text="Public - (Anyone Can see it)", Value = "Public" },
- new SelectListItem{ Text="Restricted - (Only those I invite can see it)", Value = "Restricted" },
- }, new { @class = "btn font-weight-normal" })
- </div>
- <span asp-validation-for="Privacy" class="text-danger"></span>
- </div>
- <div class="form-group">
- <label asp-for="User_Chosen_Name" class="control-label">Give a Name</label>
- <input asp-for="User_Chosen_Name" class="form-control" />
- <span asp-validation-for="User_Chosen_Name" class="text-danger"></span>
- </div>
- <div class="form-group">
- </div>
- </form>
- function ehi() {
-
- fd = new FormData($(this)[0]);
- FormData = $("#List_Form").serialize()
-
- $.ajax({
- type: "POST",
- url: "/Lists/Lists_Create",
- contentType: false,
- processData: false,
- data: fd,
- success: function (message) {
- alert(message.one + " 2 "+ message.two );
- },
- error: function (message) {
- alert('There was an error');
-
- }
- });