I have a form in an html page. I want to submit values to the following api using ajax.
{
"userName": "john",
"description": "funny dood",
"address":
{
"addressLine1": "house number from formdata",
"addressLine2": "some value picked from form",
"daDa": "some val from form"
}
}
I am using the following snippet to submit to the api using jquery ajax:
function AjaxSubmit(form_Data){
var ajaxOptions =
{
type:"POST",
contentType: "multipart/form-data",
url: "/api/Users/",
data: form_Data,
success: function (result) {
alert(result);
window.location.href = "/Home/Index"
}
}
if ($(form_Data).attr('enctype') == "multipart/form-data") {
ajaxOptions['contentType'] = false;
ajaxOptions['processData'] = false;
}
$.ajax(ajaxOptions);
return false;
}
The issue is how can i pass the address values to various fields inside the address object.
The api is built on .net core, just fyi.
Thanks 🙂
2
Answers
Is your problem that how to use JS getting an object
form_Data
?Maybe this is your issue:
parametername is varibales in the controller.