I have the following code that displays session data. The problem is even if the session matters, and ajax receives this data, the warning I put below the getValFromSession (qes) function call always shows null data. I think this is due to the asynchronous execution of ajax using javascript. So I added extra code as shown in the function
getValFromSession (qid). How can I overcome this asynchronous problem?
var qes=$('#qsid_'+q).val(); var res=getValFromSession(qes); alert(res);//always shows null value $('#select_'+).val(parseInt(res)); function getValFromSession(qid) { return $.ajax({ url : site_url_js+"controller/getValFromSession", type : "POST", data : "qid="+qid, cache: false, async: false }).responseText; } /*controller*/ function getValFromSession() { echo $_SESSION['time'][$_REQUEST['qid']]; }
source share