Q:

code to get title from list and assign to txtbox..but control doesn't reaches ajax block

var qString = null ;
$(document).ready(function () {
try
{
    getDetails();
}
catch(e)
{
    alert("error occured at ready method" + e.message);
}
});
if(qString ! = null)
{

                $.ajax({  
                    url:  _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbyTitle('My list')/items/?$select=Title&$filter=ID eq "+qString,                   
                    method: "GET",  
                    headers: { "Accept": "application/json; odata=verbose" },  
                    success: function (data)  
                    {  
            onSuccessResult(data);

            },
                error: function (data)  
                {  
                    $('body').html(data);  
                    console.log("error");  
                }  
            });
}

function onSuccessResult(data)
{
$.each(data.d.results, function(index, item){  
                            var title= (item["title"]); 
                $('#TitleId').val(title); });

  }

A:

qString= null;
$( document ).ready(function() { 
     var qString =  getdetails();

     if(qString ! = null)
    {
                $.ajax({  
                    url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbyTitle('My list')/items/?$select=Title,Name,Age,DOB,Indian&$filter=ID eq "+qString,  

                    method: "GET",  
                    headers: { "Accept": "application/json; odata=verbose" },  
                    success: function (data)  
                    {  

            $.each(data.d.results, function(index, item){

                 var title  = item. Title; 
                 var name   = item. Name; 
                 var dob    = item. DOB;  
                 var age    = item. Age;
                 var indian = item. Indian ;
                 var address = item. Address;
                 document.getElementById('AddressId').value = strip(item. Address);
                 document.getElementById('DOBId').value = getDate(item. DOB);
                 $('#TitleId').val(title); 
                 $('#NameId').val(name);
                 $('#AgeId').val(age);
                // $('#DOBId').val(dob);
                 $('#IndianId').val(indian);
                                             });       
            },
                error: function (data)  
                {  

                    $('body').html(data);  
                    console.log("error"); 
                }  
            });
    }
});

function strip(html)
{
   console.log(html);
   var tmp = document.createElement("DIV");
   tmp.innerHTML = html;
   console.log("text" + tmp.textContent);
   console.log("html" + tmp.innerHtml);
   return tmp.textContent || tmp.innerText || "";
}
function getDate(stringDate)
{
  var todayTime = new Date(stringDate);

   return todayTime.toLocaleDateString();
}
function getdetails() 
{
   var result =  window.location.href.split("?ID=")[1];
  return result;
}

