Help getting error message from json object
Posted: Mon Aug 25, 2014 10:11 am
We are not getting the error message, that should match with the error_code
We sending the code and the object contains the error/success message to show!!!
This seems to almost works. It is part of Jquery Validations, once the field or submit button is clicked. It looks for error on field. then Enter the Ajax Funciton which is to parse the error code and the out put the error message which is coming from json object.
The code is not returning the error message, on line (alert(data))
Produces [object,object] not actual data string.
The error message does not return. Please help, is there something work with our ajax request
Here is example of the json object
We sending the code and the object contains the error/success message to show!!!
This seems to almost works. It is part of Jquery Validations, once the field or submit button is clicked. It looks for error on field. then Enter the Ajax Funciton which is to parse the error code and the out put the error message which is coming from json object.
The code is not returning the error message, on line (alert(data))
Produces [object,object] not actual data string.
The error message does not return. Please help, is there something work with our ajax request
Code: Select all
//*new style for error Messages*/
//var jsonErrors = frontEndErrorCodes;
//JC wrote.
//MG added. To retrieve Front-end error codes as well as
//Backend Error Codes
function _getErrorMessage(errorCode, message){
var errorData = JSON.stringify({error_code: errorCode, message: message});
var dataString = $.parseJSON(errorData);
$.ajax({
url: './retrieveErrorMessage.json',
type: 'POST',
data: dataString,
dataType: "json",
contentType: 'application/json',
mimeType: 'application/json',
success: function(data) {
//data = $.parseJSON(data);
alert(data);
$('.error.message').contents().find('h4').text(data.message);
// if(!vanillaeGift.notify.called) {
// $('.error.message').contents().find('h4').text(error.text());
// vanillaeGift.notify.showNotification(".error");
// }
//Bolt Notification Called and Enabled here
if(BoltNotify == true){
var spanerrorgen = $('.error.message').contents().find('h4').html(data.message);
VanillaReload.notify.showNotification(".error");
}else if(BoltNotify == true && multipleNotice ==true ){
var spanerrorgen = $('.error.message').contents().find('h4').html(data.message);
VanillaReload.notify.showNotification(".error").append(spanerrorgen);
}else{
var spanerrorgen = $("<span/>").css("color","#D00").hide().addClass("error").html(data.message);
$fieldref.parent().append(spanerrorgen)
spanerrorgen.show("fast");
}
},
error: function(data) {
//data = $.parseJSON(data);
alert(data);
$('.error.message').contents().find('h4').text(data.message);
// if(!vanillaeGift.notify.called) {
// $('.error.message').contents().find('h4').text(error.text());
// vanillaeGift.notify.showNotification(".error");
// }
//Bolt Notification Called and Enabled here
if(BoltNotify == true){
var spanerrorgen = $('.error.message').contents().find('h4').html(data.message);
VanillaReload.notify.showNotification(".error");
}else if(BoltNotify == true && multipleNotice == true ){
var spanerrorgen = $('.error.message').contents().find('h4').html(data.message);
VanillaReload.notify.showNotification(".error").append(spanerrorgen);
}else{
var spanerrorgen = $("<span/>").css("color","#D00").hide().addClass("error").html(data.message);
$fieldref.parent().append(spanerrorgen)
spanerrorgen.show("fast");
}
},
fail: function(jqXHR, textStatus) {
alert(data);
if(textStatus == "parsererror"){
return "We're Sorry a system error occured";
}
}
});
}
Code: Select all
[
{
"title": "Vanilla Reoad EN US Generic Messages",
"url_title": "vanilla_reload-en-us-gen-messages",
"entry_id": 61,
"expiration_date": null,
"error_messages_m": [
{
"row_id": 236,
"server_code": "code.ws.invalidCardNumber",
"error_code": "-1",
"message": "Invalid Details Code 111"
},
{
"row_id": 237,
"server_code": "code.ws.invalidCVV",
"error_code": "-1",
"message": "Invalid Details Code 222"
},
{
"row_id": 240,
"server_code": "code.ws.invalidInformation",
"error_code": "-1",
"message": "Invalid Details Code 333"
},
{
"row_id": 248,
"server_code": "code.ws.invalidPinNumber",
"error_code": "-1",
"message": "Invalid PIN Number"
},
{
"row_id": 249,
"server_code": "code.ws.invalidConfirmNumber",
"error_code": "-1",
"message": "Invalid Confirmation Number"
},
{
"row_id": 250,
"server_code": "code.ws.invalidZipcode",
"error_code": "-1",
"message": "Invalid US Zipcode"
},
{
"row_id": 001,
"server_code": "code.fe.InvalidData",
"error_code": "001",
"message": "Please enter a valid Info"
},
{
"row_id": 002,
"server_code": "code.fe.InvalidSelect",
"error_code": "002",
"message": "Please select valid choice"
}
],
"success_messages_m": [
{
"row_id": 238,
"form": "azpc",
"message": "You have successfully assign a Zipcode to your Account"
},
{
"row_id": 239,
"form": "news",
"message": "You have successfully signed up for our Newsletter"
},
{
"row_id": 243,
"form": "mpin",
"message": "Your Account gift Card PIN has been Cleared!"
}
]
}
]