#抓取TRC Catalogue,隔週五抓取
15 22 * * 5 [ $(( $(( $(date +\%W ) )) % 2 )) -eq 1 ] && $HOME/perl/web/getInfoFromTRC.pl > /tmp/getInfoFromTRC.log 2>&1
This man is too old to remember everything in his brain. Right now, he needs a place to write down what he has studied.
2016年11月24日 星期四
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 }
<?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 }