javascript - Why is my AJAX error not returning my Webmethod exception? -


i'm using google chrome work.

following https://stackoverflow.com/a/26003200/7204173 tried return exception webmethod. not show in console.log. thing got network tab generic error message below :

"an error occurred while updating entries. see inner exception details."

so tried below (ps : i'm sending dml database using entity framework dbcontext) :

public string adddata(myentity e) {    using(var context = new myentitymodel())    {        try        {            context.myentity.add(e);            context.savechanges();            return "success";        }catch(exception ex)        {           return "error : " + ex.message;        }     } } 

now javascript code :

function addarticle() {     var e {id : "1", value : "test"};     var dto = { 'e': e };      $.ajax({         type: "post",         contenttype: "application/json; charset=utf-8",         datatype: "json",         data: json.stringify(dto),         url: "mypage.aspx/adddata",         success: function (response) {             console.log(response);                     },         error: function (xhr, status, error) {             var exception = json.parse(xhr.responsetext);                         alert(exception.message);             console.log(exception.message);         }     }); } 

so let's put call javascript function behind input button. since database, var e {id : "1", value : "test"}; can't added twice since id primary key. still nothing in console.log ; alert box not triggered. when succeeds, console.log displays success expected.

any idea of shoud looking find error ?

have try log others errors args ?

console.log(xhr); console.log(status); console.log(error); 

you should able parse manually logs in console , find right path variable want.

update

console.log(error); answer in case of op


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -