c# - ajax posting formdata error status 200 OK -
this backend code
[httppost] public void upload() { (int = 0; < request.files.count; i++) { var file = request.files[i]; var filename = path.getfilename(file.filename); var path = path.combine(server.mappath("~/uploads/"), filename); file.saveas(path); } }` and ajax request
function uploadfiles() { var formdata = new formdata(); $.each(files, function (key, value) { formdata.append(key, value); }); $.ajax({ async: false, type: 'post', url: '/home.aspx/upload', data: formdata, datatype: 'json', contenttype: false, processdata: false, cache: false, timeout :5000, success: function (response) { alert('succes!!'); }, error: function (error) { alert("errror"); console.log(error); } }); } }); the error status 200 ok .. response text masterpage html code , file not uploaded request never went backend code because have checkpoint when debugging , never went backend code
in ajax call have delete datatype: json because files must sent multipart/form-data
function uploadfiles() { var formdata = new formdata(); $.each(files, function (key, value) { formdata.append(key, value); }); $.ajax({ async: false, type: 'post', url: '/home.aspx/upload', data: formdata, contenttype: false, processdata: false, cache: false, timeout :5000, success: function (response) { alert('succes!!'); }, error: function (error) { alert("errror"); console.log(error); } }); } });
Comments
Post a Comment