You need to pass a reference to the function so change this:
error: errorFunction()
to this:
error: errorFunction
When you put the parens there, you were actually calling the function immediately and passing it's return. Without the parens, it is just a reference to the function that can be called later by the jQuery ajax infrastructure.
To further understand what was happening, your code error: errorFunction() was calling errorFunction() immediately with no arguments (which is what you were seeing in your debugging) and then fetching the return value from that function (which is undefined) and then putting that into your data structure which was passed to the ajax call. So essentially, you were doing the equivalent of this:
$(document).ready(function () {
function errorFunction(xhr, status, error) {
console.log(xhr);
if (xhr == 'undefined' || xhr == undefined) {
alert('undefined');
} else {
alert('object is there');
}
alert(status);
alert(error);
}
// obviously, not what you intended
errorFunction();
$.ajax({
type: "POST",
url: "admPlantParametersViewEdit.aspx/GetResult",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert("success");
alert(msg.d);
},
// also not what you intended
error: undefined
});
});
If you aren't using errorFunction() in other places, then a more common way to do this is to define it inline like you did with the success handler like this:
$(document).ready(function () {
$.ajax({
type: "POST",
url: "admPlantParametersViewEdit.aspx/GetResult",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert("success");
alert(msg.d);
},
error: function(xhr, status, error) {
console.log(xhr);
if (xhr == 'undefined' || xhr == undefined) {
alert('undefined');
} else {
alert('object is there');
}
alert(status);
alert(error);
}
});
});