Help getting error message from json object

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


//*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";
}
}
});

}

Here is example of the json object


[
    {
        "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!"
            }
        ]
    }
]

Well, first off let’s remove the commented out code, any code which does not appear to be related to the current problem and give the code its correct indentation:

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) {
      alert(data);
    },
    error: function(data) {
      alert(data);
    }, 
    fail: function(jqXHR, textStatus) {
      alert(data);
      if(textStatus == "parsererror"){
        return "We're Sorry a system error occured";
      }
    }
  });
}

This is a bit more manageable.

Now it appears that there are a couple of things that are incorrect:

url: './retrieveErrorMessage.json',

As you doubtless know, the url attribute is a string containing the URL to which the request is sent.
This should be a PHP script (or some other such server side language), which will return a response which will then be available to you in your success callback (assuming things went well).

JSON is however a format for storing and exchanging data, so it would be interesting to find out what you are attempting here.

Did you mean

url: './retrieveErrorMessage.php',

or is something else going on?

We got the entire response back. - console Log

What we need from the response is whats in the respsonText.
how would we look at only the responseText and get the value that mathces the key

error_code == data.responseText.message??


"[ { "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" }, { "row_id": 254, "server_code": "code.fe.InvalidPinNumber", "error_code": "100", "message": "Please enter a valid Log In ID" }, { "row_id": 255, "server_code": "code.fe.invalidConfirmNumber", "error_code": "101", "message": "Please enter a valid Confirmation Number" }, { "row_id": 241, "server_code": "code.fe.invalidCardNumber", "error_code": "110", "message": "Invalid Card Number" }, { "row_id": 242, "server_code": "code.fe.invalidCVV", "error_code": "111", "message": "Invalid CVV" }, { "row_id": 253, "server_code": "code.fe.invalidExp", "error_code": "112", "message": "Invalid Expiration Date" }, { "row_id": 257, "server_code": "code.fe.invalidZipcode", "error_code": "120", "message": "Please enter a valid ZIP Code" }, { "row_id": 256, "server_code": "code.fe.invalidScoopEmail", "error_code": "200", "message": "Please enter a valid Email address" } ], "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!" } ] }]"


Please advise

Why are there quotes around the response?

If you remove the quotes and run it through JSON Lint, the code you posted doesn’t validate.
The linter complains about these two lines:

45:                 "row_id": 001,
51:                 "row_id": 002,

These must be:

45:                 "row_id": 1,
51:                 "row_id": 2,

or:

45:                 "row_id": "001",
51:                 "row_id": "002",

And I don’t really understand the question, I’m afraid.
Could you rephrase it?

Here is fixed json obj, please anyone can you tell me what I am missing to ge this to work.

Getting error, code back not get specific error code.



[
    {
        "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": 100,
                "server_code": "code.fe.InvalidData",
                "error_code": "001",
                "message": "Please enter a valid Info"
            },
            {
                "row_id": 200,
                "server_code": "code.fe.InvalidSelect",
                "error_code": "002",
                "message": "Please select valid choice"
            },
            {
                "row_id": 254,
                "server_code": "code.fe.InvalidPinNumber",
                "error_code": "100",
                "message": "Please enter a valid Log In ID"
            },
            {
                "row_id": 255,
                "server_code": "code.fe.invalidConfirmNumber",
                "error_code": "101",
                "message": "Please enter a valid Confirmation Number"
            },
            {
                "row_id": 241,
                "server_code": "code.fe.invalidCardNumber",
                "error_code": "110",
                "message": "Invalid Card Number"
            },
            {
                "row_id": 242,
                "server_code": "code.fe.invalidCVV",
                "error_code": "111",
                "message": "Invalid CVV"
            },
            {
                "row_id": 253,
                "server_code": "code.fe.invalidExp",
                "error_code": "112",
                "message": "Invalid Expiration Date"
            },
            {
                "row_id": 257,
                "server_code": "code.fe.invalidZipcode",
                "error_code": "120",
                "message": "Please enter a valid ZIP Code"
            },
            {
                "row_id": 256,
                "server_code": "code.fe.invalidScoopEmail",
                "error_code": "200",
                "message": "Please enter a valid Email address"
            }
        ],
        "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!"
            }
        ]
    }
]