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 :

enter image description here

it shows value need why return complete html well?

  • you not need jsonrequestbehavior.allowget. must used get requests in order protect against specific attack involving json requests. , in code using post verb.

  • you should use follow code in order success string received server.

    success: function (response) { alert('success ' + response.success); }


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -