這是負責抓取Ajax要的資料的頁面程式。

<?php session_start();  ?>
<?php
$password=$_SESSION["password"];
$numberforsession=$_SESSION["number"];
$whichone=$_GET['i'];
require_once("../../Company_connect.php");
$sqlfromwe="select * from workexperience where (usernumber='$numberforsession' and whichone='$whichone')";
$resultfromwe=mysql_query($sqlfromwe,$link);
$result1fromwe=mysql_fetch_assoc($resultfromwe);
if($resultfromwe==true){
$workyear=$result1fromwe["workyear"];
$companyname=$result1fromwe["companyname"];
$companyscale=$result1fromwe["companyscale"];
$jobname=$result1fromwe["jobname"];
$jobcategory=$result1fromwe["jobcategory"];
$responsibility=$result1fromwe["responsibility"];
$controlman=$result1fromwe["controlman"];
$beginyear=$result1fromwe["beginyear"];
$beginmonth=$result1fromwe["beginmonth"];
$endyear=$result1fromwe["endyear"];
$endmonth=$result1fromwe["endmonth"];
$stillinjob=$result1fromwe["stillinjob"];
$jobcontent=$result1fromwe["jobcontent"];
$whichone=$result1fromwe["whichone"];

echo $workyear.",".$companyname.",".$companyscale.",".$jobname.",".$jobcategory.",".$responsibility.",".$controlman.",".$beginyear.",".$beginmonth.",".$endyear.",".$endmonth.",".$stillinjob.",".$jobcontent.",".$whichone;
}else{
$message=="失敗";
echo $message;
}

?>

下面的是ajax()的執行

<script>

function forthefirst(x){
 if(document.getElementById('first').style.display=="none" && document.getElementById('new').style.display==""){
 alert("您正在編輯新的工作資料,請先儲存檔案或是關閉檔案或是刪除檔案再繼續。");
 return false;
 }else{
 document.getElementById('first').style.display="";
 document.getElementById('new').style.display="none";
 createXHR();
  if(x==1)
  var i="1";
  else if(x==2)
  var i="2";
  else if(x==3)
  var i="3";
  var url='0427WorkExperienceBeGet.php?i='+i+'&ts='+new Date().getTime();
  xmlHttp.open('GET',url,true);
  xmlHttp.onreadystatechange=catchResult;
  xmlHttp.send(null); 
 }
}
function catchResult(){
  if(xmlHttp.readyState==4){
  s=xmlHttp.responseText;
      if(xmlHttp.status ==200){
    var arrayStr=s.split(",");  
     document.getElementById("companyname").value=arrayStr[1];  
     if(arrayStr[2]=="1-30人")
     document.form1.companyscale.value="0";
     else if(arrayStr[2]=="30-100人")
     document.form1.companyscale.value="1";
     else if(arrayStr[2]=="100-500人")
     document.form1.companyscale.value="2";
     else if(arrayStr[2]=="500人以上")
     document.form1.companyscale.value="3";
    
     document.getElementById("jobname").value=arrayStr[3];
    
     if(arrayStr[4]=="全職")
     document.form1.jobcategory.value="0";
     else if(arrayStr[4]=="兼職")
     document.form1.jobcategory.value="1";
     else if(arrayStr[4]=="高階")
     document.form1.jobcategory.value="2";
    
     if(arrayStr[5]=="有")
     document.form1.response.value="0";
     else
     document.form1.response.value="1";
    
     if(arrayStr[6]=="4人以下")
     document.form1.controlman.value="0";
     else if(arrayStr[6]=="5-8人")
     document.form1.controlman.value="1";
     else if(arrayStr[6]=="9-12人")
     document.form1.controlman.value="2";
     else if(arrayStr[6]=="13人以上")
     ddocument.form1.controlman.value="3";
    
     var i;
     for(i=2010;i>=1961;i--){
    if(arrayStr[7]==i)
    document.form1.beginyear.value=i;
     }
     var j;
     for(j=1;j<=12;j++){
    if(arrayStr[8]==j)
    document.form1.beginmonth.value=j;
     }
     for(i=2010;i>=1961;i--){
    if(arrayStr[9]==i)
    document.form1.endyear.value=i;
     }
     for(j=1;j<=12;j++){
    if(arrayStr[10]==j)
    document.form1.endmonth.value=j;  
     }
     if(arrayStr[11]=="on")
      document.form1.stillinjob.value=0;
     else
     document.form1.stillinjob.value=1;
    
     document.form1.jobcontent.value=arrayStr[12];
     document.getElementById("whichone").value=arrayStr[13];   
      }
  } 
}</script>

 

重點在換色的地方,把很多的資料用逗號區分存進陣列就可以使用了。

創作者介紹
創作者 有關於網頁設計和程式.... 的頭像
ray730727

有關於網頁設計和程式....

ray730727 發表在 痞客邦 留言(0) 人氣( 545 )