javascript - ajax call returns values and my html page -
i performing ajax call controller following code:
$.ajax({ type: "post", url: "@url.action("uploadimage", "item")", data: '{ "imagedata" : "' + image + '" }', contenttype: "application/json; charset=utf-8", datatype: "json", success: function (success) { alert('success ' + success.responsetext); }, error: function (response) { alert(response.responsetext); } }); this controller :
[httppost] public actionresult uploadimage(string imagedata) { string imagename = guid.newguid().tostring(); try { productmanager pm = new productmanager(); pm.addnewproduct(imagename); }catch(exception e) { writetolog(e); } return json(new { success = imagename }, jsonrequestbehavior.allowget); } it gets controller , addnewproduct function runs successfully. problem want return image name created within controller. works return complete html page. alert on success , when error occurs somehow ends in error following alert :
it shows value need why return complete html well?
you not need
jsonrequestbehavior.allowget. must usedgetrequests in order protect against specific attack involving json requests. , in code usingpostverb.you should use follow code in order
successstring received server.success: function (response) { alert('success ' + response.success); }

Comments
Post a Comment