I have the following code and i am trying to retrieve the userid , firstname and some values from JSON but I am getting undefined.
How can i fix this?
 function getVal(val1,val2) {       
    var myval2 =URL +"webUser?email="+email;
    var uId='';
    $.ajax({
        url: myval2,
        dataType: "json",
         cache: false, 
        success: function(data, textStatus, jqXHR) {
            jQuery.each(data, function(k,v) {
             console.log( " k "  +k  + " v" + v);
             uId =v.uId;
             });       
    },
        error: function(jqXHR, textStatus, errorThrown) {
            console.log('FAILED to get  JSON from AJAX call' + jqXHR + textStatus + errorThrown);
        }
    });       
      console.log("userid " +userId);
     return userId;
   }    
JSON
{
  "userId": 2,
  "emailAddress": "some@some.com",
  "roleId": 1,
  "firstName": "Hulk",
  "lastName": "Ogan",
  "company": "MTT",
  "title": "Lord Vader",
  "phoneWork": "",
  "phoneMobile": "",
  "lastModifiedBy": "system",
  "versionNumber": 1
}
 
     
     
     
    