メインファイルがあります
index.php
のような他の 4 つのファイルを含めます
header_get_started.php,
content_main.php,
right_sec_home.php,
footer.php.
これが私のコードです
"index.php"
<script src="js/ajax.js"></script>
<?php include_once('header_getstarted.php'); ?>
<?php include_once('content_main.php'); ?>
<?php include_once('right_sect_home.php'); ?>
<?php include_once('footer.php'); ?>
"header_getstarted.php"
<span class="select_input">
<?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;'")
?>
<input type="submit" name="" class="sub_bg" value="" onclick="get_request_by_command($('#cmb_command').val());">
</span>
header_get_started.php
選択ボックスから任意のコマンドを選択するときに、その id を に割り当てたいと思います$_SESSION['id']
。
選択ボックスのオンクリック メインコンテンツを更新できる ajax リクエストがあります ( content_main.php
)。right_sec_home.php
また、別のページで選択した ID を使用して、そのコンテンツを更新したいと考えています。
2ページ目のJSファイルにphpセッションIDを割り当てるにはどうすればよいですか?
私のJSファイルは
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='<img src="images/loader.gif" />';
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("<span id='cmdTitle'>"+cmdTitle+"</span>);
$('#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);
}
}
この jQuery 関数を使用して、ajax リクエストを作成し、id を"request_by_command_tbl.php"
ファイルに送信します。
"request_by_command_tbl.php"
私が割り当てたファイルでは、
$_SESSION['id'] = $_REQUEST['id'];
$_SESSION['id']
また、これをright_sec_home.php
同時に入れたいです。$_SESSION['id']
ajaxリクエストを送信する前に、jQueryスクリプトファイルでphpを割り当てる方法も同様です。
私の他のファイル
"content_main.php"
<div id="request_list"> </div>
<div> </div>
<div id="add_space"></div>
セッションIDが必要な右側のセクションのホームファイル
"right_sec_home.php"
<?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;
}
これが十分に明確であることを願っています。何か案は?
助けてください。