c# - MVC4 AJAX post JSON -


this function, post json only

function test() {             var imgfile = document.getelementbyid('image');             //            var imgdata = json.stringify(getbase64image(imgelem));             //var imgdata = convert.formbase64string(imgelem);              $.ajax({                 type: 'post',                 datatype: 'json',                 url: "http://localhost:59102/contacts/addcontact",                 data: "json=" + "{\"token\":\"8mvm/ns1ofpu+nlqlbjjqxj7kji=vylgi2gekkggtdt0babraw==\"}",                  success: function (returnpayload) {                     console && console.log("request succeeded");                 },                 error: function (xhr, ajaxoptions, thrownerror) {                     console && console.log("request failed");                 },                  processdata: false,                 async: false             }); 

and dont know how add data, image, need post json , image

this controller

[httppost]         [allowanonymous]         public jsonresult addcontact(string json, httppostedfilebase file)         {} 

you can't upload files via ajax (by design) unless use plugin utilises other 'technology' such flash, or iframes - security measure javascript reading local files on machine not best idea

there's an option here: http://jquery.malsup.com/form/

...otherwise suggest looking 1 of many other alternatives!


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -