Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I assign session id of php in a jQuery file?
    text
    copied!<p>I have a main file </p> <pre><code>index.php </code></pre> <p>in which I include four other files like </p> <pre><code>header_get_started.php, content_main.php, right_sec_home.php, footer.php. </code></pre> <p>Here is my code</p> <pre><code>"index.php" &lt;script src="js/ajax.js"&gt;&lt;/script&gt; &lt;?php include_once('header_getstarted.php'); ?&gt; &lt;?php include_once('content_main.php'); ?&gt; &lt;?php include_once('right_sect_home.php'); ?&gt; &lt;?php include_once('footer.php'); ?&gt; "header_getstarted.php" &lt;span class="select_input"&gt; &lt;?php $sqlCmd = "some query"; echo combo('cmb_command','custom-class1 custom-class2','cmd_name','cmd_id','0',$sqlCmd,'sendpostmtu()' $width="style='width:250px;cursor:pointer;'") ?&gt; &lt;input type="submit" name="" class="sub_bg" value="" onclick="get_request_by_command($('#cmb_command').val());"&gt; &lt;/span&gt; </code></pre> <p>In <code>header_get_started.php</code> When select any command from select box, I want to assign it's id to <code>$_SESSION['id']</code>. </p> <p>Onclick of selection box I have an ajax request which can refresh the main content (<code>content_main.php</code>). Also I want that selected id in another page in <code>right_sec_home.php</code> to refresh it's content. </p> <p>How can I assign the php session id in JS file for 2nd page?</p> <p>My JS file is</p> <pre><code>function get_request_by_command (commandId) { var cmdTitle=$('#cmb_command :selected').text(); if(cmdTitle=="") { cmdTitle='ABC'; } $("#main_wrap").hide(); if(cmdTitle=='--Select--'){ $("#cmdTitle").html(""); }else{ $("#cmdTitle").html(cmdTitle); } $("#cmbs_cmd").val(commandId); document.getElementById('request_list').innerHTML='&lt;img src="images/loader.gif" /&gt;'; var strURL="request_by_command_tbl.php?id="+commandId; var req = getXMLHTTP(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4) { // only if "OK" if (req.status == 200) { var ret = req.responseText; $("#requestTitle").html("&lt;span id='cmdTitle'&gt;"+cmdTitle+"&lt;/span&gt;); $('#request_list').html(''); $('#request_list').html(ret); $('#main').show(); $("#searchDiv").show(); } else { alert("There was a problem while using XMLHTTP:\n" + req.statusText); } } } req.open("GET", strURL, true); req.send(null); } } </code></pre> <p>With using this jQuery function, I have created an ajax request, and send the id to the <code>"request_by_command_tbl.php"</code> file. </p> <p>In <code>"request_by_command_tbl.php"</code> file i assigned,</p> <pre><code>$_SESSION['id'] = $_REQUEST['id']; </code></pre> <p>Also I want this <code>$_SESSION['id']</code> in <code>right_sec_home.php</code> at same instant. So is their any way to assign php <code>$_SESSION['id']</code> in the jQuery script file before sending ajax request. </p> <p>My other files</p> <pre><code>"content_main.php" &lt;div id="request_list"&gt; &lt;/div&gt; &lt;div&gt; &lt;/div&gt; &lt;div id="add_space"&gt;&lt;/div&gt; </code></pre> <p>Right section home file in which i need session id</p> <pre><code> "right_sec_home.php" &lt;?php function getRequestByMonth($month, $year, $id){ $que ="SELECT distinct(MS.date) FROM commands AS MC , ranks AS MR ,steady_tours AS MST, preferred_tours AS MPT, registration AS MMS where date_format(rm_date, '%c-%Y') = '".$month."-".$year."' AND MMS.cmd_id ='".$_SESSION['id']."' order by MMS.date"; $res = mysql_query($que); while($rows[]=mysql_fetch_array($res)){} foreach ($rows as $res): if($res['date'] == "") continue; $dt = date("Y-n-j", strtotime($res['date'])); $return[getDateB($dt)] = $res['date']; endforeach; return $return; } </code></pre> <p>I hope that this is clear enough. Any ideas? </p> <p>Please help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload