javascript - How can I send files along with other field's data to webmethod is asp.net using jquery ajax call? -
i have webform has x number of textboxes , y number of dropdowns etc using code send data webmethod @ server:
$.ajax({ type: "post", url: "suppliermaster.aspx/registersupplier", data: json.stringify({ id: $('#txtbidderid').val(), bidamt: $('#txtbidamt').val() }), contenttype: "application/json; charset=utf-8", datatype: "json", async: true, success: function (data, status) { alert(data.d); }, failure: function (data) { alert(data.d); }, error: function (data) { alert(data.d); } });
now problem want include file attachments on form. how add files data:
of $.ajax
method? not want use external plugins etc unless absolutely necessary.
lets modify data object :
var datatosend = {}; datatosend.id = $('#txtbidderid').val() datatosend.bidamt = $('#txtbidamt').val() datatosend.append( 'file', input.files[0] );
what webmethod armument like? example lets suppose looks of now: [webmethod] public static string submitbid(string id, string bidamt.....)
you can try this. may need manipulate content type.
var datatosend = new formdata(); datatosend.append( 'file', input.files[0] ); $.ajax({ url: "suppliermaster.aspx/registersupplier", data: datatosend, processdata: false, contenttype: false, type: 'post', success: function(data){ alert(data); } });
Comments
Post a Comment