標籤

4GL (1) 人才發展 (10) 人物 (3) 太陽能 (4) 心理 (3) 心靈 (10) 文學 (31) 生活常識 (14) 光學 (1) 名句 (10) 即時通訊軟體 (2) 奇狐 (2) 爬蟲 (1) 音樂 (2) 產業 (5) 郭語錄 (3) 無聊 (3) 統計 (4) 新聞 (1) 經濟學 (1) 經營管理 (42) 解析度 (1) 遊戲 (5) 電學 (1) 網管 (10) 廣告 (1) 數學 (1) 機率 (1) 雜趣 (1) 證券 (4) 證券期貨 (1) ABAP (15) AD (1) agentflow (4) AJAX (1) Android (1) AnyChart (1) Apache (14) BASIS (4) BDL (1) C# (1) Church (1) CIE (1) CO (38) Converter (1) cron (1) CSS (23) DMS (1) DVD (1) Eclipse (1) English (1) excel (5) Exchange (4) Failover (1) Fedora (1) FI (57) File Transfer (1) Firefox (3) FM (2) fourjs (1) Genero (1) gladiatus (1) google (1) Google Maps API (2) grep (1) Grub (1) HR (2) html (23) HTS (8) IE (1) IE 8 (1) IIS (1) IMAP (3) Internet Explorer (1) java (4) JavaScript (22) jQuery (6) JSON (1) K3b (1) ldd (1) LED (3) Linux (117) Linux Mint (4) Load Balance (1) Microsoft (2) MIS (2) MM (51) MSSQL (1) MySQL (27) Network (1) NFS (1) Office (1) OpenSSL (1) Oracle (126) Outlook (3) PDF (6) Perl (60) PHP (33) PL/SQL (1) PL/SQL Developer (1) PM (3) Postfix (2) postfwd (1) PostgreSQL (1) PP (50) python (5) QM (1) Red Hat (4) Reporting Service (28) ruby (11) SAP (234) scp (1) SD (16) sed (1) Selenium (3) Selenium-WebDriver (5) shell (5) SQL (4) SQL server (8) sqlplus (1) SQuirreL SQL Client (1) SSH (2) SWOT (3) Symantec (2) T-SQL (7) Tera Term (2) tip (1) tiptop (24) Tomcat (6) Trouble Shooting (1) Tuning (5) Ubuntu (37) ufw (1) utf-8 (1) VIM (11) Virtual Machine (2) VirtualBox (1) vnc (3) Web Service (2) wget (1) Windows (19) Windows (1) WM (6) Xvfb (2) youtube (1) yum (2)

2016年11月24日 星期四

crontab 隔週執行程式

#抓取TRC Catalogue,隔週五抓取
15 22 *    * 5   [ $((  $(( $(date +\%W ) )) % 2 )) -eq 1 ] && $HOME/perl/web/getInfoFromTRC.pl > /tmp/getInfoFromTRC.log 2>&1

2016年11月9日 星期三

PHP 和 Javascript (AJAX) 數值傳遞實例

1. 由於不同server,所以PHP需要增加以下紅字部分

<?php
header("Access-Control-Allow-Origin: *");

$v = $_REQUEST;

foreach($v as $i=>$v)
{
  #$temp = $temp."$i=$v,";
  if ($i == "occ03") {$occ03 = $v;}
  if ($i == "occ11") {$occ11 = $v;}
}

$dbconn = oci_connect("xxx","yyy",
                      "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xxx.xxx.xxx)(PORT=1521))(CONNECT_DATA=(SID=xxx)))",
                      "AL32UTF8");

$sql = "
   select count(*)
     from occ_file
    where occ03 = substr(:occ03,1,2)
      and occ11 = :occ11
    order by 1
";

$stid = oci_parse($dbconn, $sql);
oci_bind_by_name($stid,":occ03",$occ03);
oci_bind_by_name($stid,":occ11",$occ11);

//echo "2";
oci_execute($stid);
while ($row = oci_fetch_row($stid)) {
   echo "$row[0]";
   #echo "var occ11_cnt=$row[0];";
}

oci_close($dbconn);
?>

2. 由於是asynch,所以javascript在判斷時要在 onreadystatechange 就改變原本網頁element的值,另外sleep兩秒(因為asynch,太短時間怕抓到為修改以前的值)
3. 也許使用 XmlHttpRequest 的 sync option (底下true的地方) 也可以,但我未測試




 function ... (
  chkOCC11();
  sleep(2000);
  var str = document.getElementById("occ11").value;
  if (str.match("請重新輸入")) {
     //alert("統一編號重複,請確認")
     return false;
  };

  return true;
)

function chkOCC11() {
   var occ03 = document.getElementById("occ03").value;
   var occ11 = document.getElementById("occ11").value;

   var http ;
   if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
      http = new XMLHttpRequest();
   } else {// code for IE6, IE5
      http = new ActiveXObject("Microsoft.XMLHTTP");
   }

   var url = "http://10.1.100.201/eip/action/SA001/chkOCC11.php";
   var params = "occ03=" + occ03.substr(0,2) + "&occ11=" + occ11;
   var occ11_cnt;

   if ("withCredentials" in http) {
      http.open('POST', url + "?" + params, true);
    }
   else if (typeof XDomainRequest != "undefined") {
      http = new XDomainRequest();
      http.open('POST', url + "?" + params, true);
   }

   http.onreadystatechange = function() {//Call a function when the state changes.
      if(http.readyState == 4 && http.status == 200) {
         occ11_cnt = http.responseText;
         if (occ11_cnt > 0) {
            document.getElementById("occ11").value = "請重新輸入";
            alert("統一編號重複,請重新輸入");
         }
      }
   }
   http.send(null);
}

 function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

4.2017/05/02 經過測試,使用同步,不使用非同步的方式就可以檢查值的正確性
 5313 function chkTC_CTR11() {
5314    var ta_occ09 = document.getElementById("ta_occ09").value;
5315    var occ11 = document.getElementById("occ11").value;
5316
5317    var http ;
5318    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
5319       http = new XMLHttpRequest();
5320    } else {// code for IE6, IE5
5321       http = new ActiveXObject("Microsoft.XMLHTTP");
5322    }
5323
5324    var url = "http://10.1.100.201/eip/action/SA001/chkTC_CTR11.php";
5325    var params = "tc_ctr11_03=" + ta_occ09.substr(0,2) + "&tc_ctr11_01=" + occ11;
5326    var result;
5327
5328    if ("withCredentials" in http) {
5329       http.open('POST', url + "?" + params, false); //false : 同步請求 ; true 非同步請求
5330       //http.open('POST', url + "?" + params, true); //false : 同步請求 ; true 非同步請求
5331     }
5332    else if (typeof XDomainRequest != "undefined") {
5333       http = new XDomainRequest();
5334       http.open('POST', url + "?" + params, false);
5335       //http.open('POST', url + "?" + params, true);
5336    }
5337    //http.timeout = 2000;
5338
5339    http.onreadystatechange = function() {//Call a function when the state changes.
5340       if(http.readyState == 4 && http.status == 200) {
5341          //alert("http.responseText = " + http.responseText);
5342          result = http.responseText;
5343          if (result == 1) {
5344             document.getElementById("ta_occ09").value = "";
5345             alert("此為業務區舊客戶,不可新增在不同分公司的業務區域");
5346          }
5347          if (result == 2) {
5348             document.getElementById("ta_occ09").value = "";
5349             alert("此為其他分公司客服區舊客戶,不可新增在業務區,請新增在客服區");
5350          }
5351       }
5352    }
5353    http.send(null);
5354 }