javascript - API POST call with large model, need some guidance -


i have large form (50 fields) , need pass api call.

doing in javascript file pretty large serialize data on form proper model.

is possible call controller, , use model pass through api url?

basically want know easy way take form data , turn serialized data based on model.

thanks!

edit: easy meaning don't have take each form input , create model them

my code below, need fill out bunch of fields (i haven't tried other way)

 $("#submit").click(function () {             var name = $("#name").val();             var address = $("#address").val();             var dob = $("#dob").val();             $.ajax({                 url: "http://localhost:49493/api/values",                 type: "post",                 data: json.stringify([name, address, dob]),                  //instead of 3 fields, have 50                 contenttype: 'application/json; charset=utf-8',                 success: function (data) { },                 error: function () { alert('error'); }             });         }); 

jquery has function can use $("#myform").serialize()

http://api.jquery.com/serialize/

$("#submit").click(function () {             var mydata = $("#myform").serialize()              $.ajax({                 url: "http://localhost:49493/api/values",                 type: "post",                 data: mydata,                  //instead of 3 fields, have 50                 contenttype: 'application/json; charset=utf-8',                 success: function (data) { },                 error: function () { alert('error'); }             });         }); 

(although 50 form field sounds quite large. might want reconsider design, perhaps there valid use case)


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -