Ajax success value to parent function

Ajax success value to parent function

Hi I am trying to get the  Ajax function return values.

  1. <script type = "text/javascript"> function GetString(key) { alert(key); var keyValue = ""; $.ajax({ type: "POST", url: "ajax.aspx/GetString", data: '{key: "' + key + '" }', contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { keyValue = response.d; alert(keyValue); }, failure: function (response) { alert(response.d); } }); return keyValue; } </script> <script type = "text/javascript"> function Getdata(key) { var data = GetString(key); alert(data); } </script>

    <input id="btnGetValue" type="button" value="Show EmpName" onclick = "Getdata('1001')" />
  2. The reason being i am planning to have the Ajax call in .js file and i don't want to write the code in every page. So that i can call the funtion anywhere just referring my .js file.

    But am getting empty value in in the alert. Any suggestion please