0

I am using jQuery in one of my current project and face some problem in incorporation.

Here is the functions which I am using as follows:

$.fn.getEcval = function(c){
    var objType = c.type;  // get the value of 'pul' through alert.

    var hdf = $('input[name="eq"]').val();
    var objHdf = jQuery.parseJSON(hdf);
    alert(objHdf.objType); // get "undefined" through alert
};

$.fn.get_phnum = function(){    
    var url = $.fn.getEcval({'type':'pul'});
};

In $.fn.getEcval I send the parameter to get the value. I put the JSON string in my HTML hidden field. I get the string in the variable "hdf" which I have declared in the function.
When I run it in the browser the alert function return undefined. But instead of objType if I put pul (i.e alert(objHdf.pul)) I get the proper output.

Here is the JSON data as stated below:

{
  "flg": 1,
  "alrd": 1,
  "drplen": 2,
  "qrr": "7055eced15538bfb7c07f8a5b28fc5d07055eced15538bfb",
  "wfa": 0,
  "ctp": "1",
  "pul": "b7c07f8a5b28fc5"
}

Any help in this regard will be highly appreciated.

1
  • need to know your php script response. how you write your php or server script. You must return a string with proper json format. Commented Sep 2, 2013 at 7:41

1 Answer 1

2

use the array notation.

 alert(objHdf[objType]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.