2015年12月19日 星期六

jQuery AJAX

jQuery AJAX Methods

AJAX is the art of exchanging data with a server, and update parts of a web page - without reloading the whole page.
The following table lists all the jQuery AJAX methods:
MethodDescription
$.ajax()Performs an async AJAX request
$.ajaxPrefilter()Handle custom Ajax options or modify existing options before each request is sent and before they are processed by $.ajax()
$.ajaxSetup()Sets the default values for future AJAX requests
$.ajaxTransport()Creates an object that handles the actual transmission of Ajax data
$.get()Loads data from a server using an AJAX HTTP GET request
$.getJSON()Loads JSON-encoded data from a server using a HTTP GET request
$.getScript()Loads (and executes) a JavaScript from a server using an AJAX HTTP GET request
$.param()Creates a serialized representation of an array or object (can be used as URL query string for AJAX requests)
$.post()Loads data from a server using an AJAX HTTP POST request
ajaxComplete()Specifies a function to run when the AJAX request completes
ajaxError()Specifies a function to run when the AJAX request completes with an error
ajaxSend()Specifies a function to run before the AJAX request is sent
ajaxStart()Specifies a function to run when the first AJAX request begins
ajaxStop()Specifies a function to run when all AJAX requests have completed
ajaxSuccess()Specifies a function to run when an AJAX request completes successfully
load()Loads data from a server and puts the returned data into the selected element
serialize()Encodes a set of form elements as a string for submission
serializeArray()Encodes a set of form elements as an array of names and values

AJAX

AJAX 概念:

AJAX




Create an XMLHttpRequest Object



var xhttp;
if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
    } else {
    // code for IE6, IE5    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}


Send a Request To a Server






Server Response






The onreadystatechange Event








<!DOCTYPE html>
<html>
<body>

<h3>Start typing a name in the input field below:</h3>

<form action=""> 
First name: <input type="text" id="txt1" onkeyup="showHint(this.value)">
</form>

<p>Suggestions: <span id="txtHint"></span></p> 

<script>
function showHint(str) {
  var xhttp;
  if (str.length == 0) { 
    document.getElementById("txtHint").innerHTML = "";
    return;
  }
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById("txtHint").innerHTML = xhttp.responseText;
    }
  };
  xhttp.open("GET", "gethint.php?q="+str, true);
  xhttp.send();   
}
</script>

</body>
</html>



showCustomer

function showCustomer(str) {
  var xhttp; 
  if (str == "") {
    document.getElementById("txtHint").innerHTML = "";
    return;
  }
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
    document.getElementById("txtHint").innerHTML = xhttp.responseText;
    }
  };
  xhttp.open("GET""getcustomer.asp?q="+str, true);
  xhttp.send();
}




2015年12月9日 星期三

DataSource->Where

如果 在 Design Type 下,該筆  Record 的 DataSource 裡面的 WHERE 有設定值
則 Run Time 時,似乎無法改變 DataSource->Where 的值

如果 在 Design Mode 裡, Record 的 DataSource 沒有設 Where
Run time ,在 BeforeBuildSelect Event 就可以設定 Where 值!

2015年12月7日 星期一

快速訂單設計記錄

這篇是寄給我自己看的,讀者看不懂就算了!

在資料庫中讀取相同的介紹會員,且還沒有完成的快速訂單中,找出最近的一筆,亦即是 id 最大的那筆,然後,設定一個 Session 給他。

在 STEP1 Page 中的 PageBeforeInitialize 中,寫:
$db = new clsDBmysql_conn(); 
$SQL = "SELECT max(qf_id) as maxid FROM quick_form WHERE refer_mem_extid='" .$_SESSION["mem_id"]."' AND finished='0';";
$db->query($SQL);
$Result = $db->next_record(); 
if ($Result) {$_SESSION["qf_id"] = $db->f("maxid");} else {$_SESSION["qf_id"] = 0;}

然後,在 Page 的 Record 中,DataSource 中,要設定該 Table ,Where 設定為:qf_id=$_SESSION["qf_id"];

這樣就可以搞定。

STEP 2, STEP 3....之後的步驟網頁,也都是一樣的設定,這樣就可以確保處裡的都是相同的一筆資料了!

上一步、下一步,都可以指稱到相同的一筆。縱使是 user 直接在 url 輸入 step2網址,也可以指到我們希望的那一筆資料。(相同會員最後未完成的那一筆記錄)。

注意:當最後一個步驟完成時,記得必需將 Finished 欄位設為"1",且將 Session 清空!表示已經完成,不會被重複處理!


DataSource->Where

DataSource->Where Run-Time Property (PHP)

Syntax

object->DataSource->Where [=value]

This property stores all conditions that are eventually used in the WHERE clause of a query that selects, updates or deletes data from the database. Programmers can add their own conditions (preserving the SQL syntax) in one of the events triggered before the final query is built and executed (i.e. BeforeBuildSelect, BeforeBuildDelete, BeforeBuildUpdate).

在CodeCharge 的 help 裡面有這一段,他說設定了DataSource->Where 是儲存了  Select, update, delete  的 WHERE 子句。
程式設計師可以分別在 BeforeBuildSelect, BeforeBuildDelete, BeforeBuildUpdate 裡面,去設定 WHERE 子句。

結果,我一開始以為,只要在 BeforeBuildSelect 中設定了 WHERE 子句,就已經設定了所有的 WHERE 子句,結果一執行的結果,Select 出來的是我要的結果沒錯,但是,一執行 Update 就整個資料庫都被 Update ,就相當於沒有 Where 一樣。(  我在 Record 的定義中,並沒有設定 WHERE)。這並不是我要的結果。

後來經過測試的結果是:原來,我必須個別去設定 BeforeBuildUpdate  的 Where,以及 BeforeBuildDelete 的 Where 才會被正確的執行。

 CodeCharge的SELECT, UPDATE, DELETE 的 WHERE 子句是個別設定的!

如何判斷現在FORM是在 insert mode? 還是 update mode?

只要用  if (empty({primary_key})) 就可以知道是否為新增模式了。 如果 {promary_key} 是空白的,那麼就是在新增模式;反之,就是更新模式。 以上。