www.webdeveloper.com
Results 1 to 5 of 5

Thread: Help getting error message

  1. #1
    Join Date
    May 2006
    Posts
    28

    Lightbulb Help getting error message

    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

    Code:
    //*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

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

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,346
    This query is best asked in the JavaScript frameworks forum.
    Last edited by jedaisoul; 08-25-2014 at 06:48 PM. Reason: *** thread moved by moderator ***
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    May 2006
    Posts
    28

    Red face We are able to get the entire json object back, but how to parse

    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??
    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": 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

  4. #4
    Join Date
    May 2006
    Posts
    28

    Post Got the JSON obj fixed, now need help getting the error message

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

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

  5. #5
    Join Date
    May 2006
    Posts
    28

    Post Getting error, code back not get specific error code.

    We are able to get there error_message into a loop in jquery as each statemement. And doing error code compare, but it only produces the last error message from the error_messages_m, array.

    Why is it not stop and taking the error that matches by errorCode == error_code.

    Code:
    	
    	//*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);
    					 // console.log(data);
    					 // console.log(errorCode);
    					 // console.log(data.error_messages_m);
    					$.each(data.error_messages_m, function(error_code, message ) {
    						 if(errorCode == message.error_code && errorCode != -1 ){	 
    									 console.log(errorCode + message.error_code);
    									 console.log(message.message);
    
                                  return false;									 
    							}
    					var message = 	message.message; 
    				   //Bolt Notification Called and Enabled here
    				   if(BoltNotify == true){ 
    						var spanerrorgen = $('.error.message').contents().find('h4').html(message);
    						 VanillaReload.notify.showNotification(".error");
    					}else if(BoltNotify == true && multipleNotice ==true ){ 	
    						var spanerrorgen = $('.error.message').contents().find('h4').html(message);
    						 VanillaReload.notify.showNotification(".error").append(spanerrorgen);			   
    					 }else{
    						var spanerrorgen = $("<span/>").css("color","#D00").hide().addClass("error").html(message);
    						$fieldref.parent().append(spanerrorgen)
    						spanerrorgen.show("fast");					
    					 }
    				  });		
    				},
    		
    			error: function(data) {
    					 //data = $.parseJSON(data);
    					 console.log(data);
    					 console.log(errorCode);
    					 console.log(data.message);
    		
    				   //Bolt Notification Called and Enabled here				
    				   if(BoltNotify == true){ 
    						var spanerrorgen = $('.error.message').contents().find('h4').html(data.error_messages_m);
    						 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";
    					}
    				}
    			
               });			
    		
    			
    	}

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles