I'm using google chrome for my work.
Following https://stackoverflow.com/a/26003200/7204173 I tried to return an exception from webmethod. But it does not show anything in the console.log. The only thing I got is from network tab the generic error message below :
"An error occurred while updating the entries. See the inner exception for details."
So what I tried is below (ps : I'm sending DML a 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 my 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 say I put it a call a the javascript function behind an input button. Since it is a database, the var e {id : "1", value : "test"};
can't be added twice since id
is a primary key. Still I get nothing in the console.log ; the alert box does not even get triggered. But when it succeeds, the console.log displays success
as expected.
Any idea of where I shoud be looking for to find my error ?