Template file:
Add a field to the Ecm_member data sheet: balance
<! DOCTYPE HTML Public "-//w3c//dtd XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD ">
<script type= "text/javascript" src= "{lib file=jquery.js}" charset= "utf-8" ></script>
<body>
<Table><TR><TD>Increase Balance: <inputtype= "text"OnBlur= "add_balance (this, ' {$info. user_id} ');"size= "ten"maxlength= "5"value= "0"></TD><TD>Increase Quantity:<spanID= "test"> </span></TD></TR>
</table>
<Script>functionadd_balance (obj,user_id) {obj.value=Obj.value.replace (/[^\d]/g,"');//replace non-digits with an emptyvarBalance_add=JQuery (obj). val ();//gets The value of the input box
Call the function inside the controller, pass two parameters Jquery.getjson ('index.php?app=member&act=add_balance&user_id='+user_id+'&balance_add='+balance_add,"',function(json) {if(json.result==1) {//use The value returned by the controller to read the alert in the form of data.variable ('Set Success'); JQuery ("#test"). HTML (balance_add); } });}</Script>
</body>
Inside the controller defines the Function:
1 functionadd_balance () {2 $model _member= & M (' member ');3 $user _id=$_request[' user_id ']?$_request[' user_id ']: ';//get method Gets the value passed over4 $balance _add=$_request[' Balance_add ']?$_request[' Balance_add ']: ';5 $user _info=$model _member->get (' user_id= ').$user _id);6 $balance=$user _info[' Balance '] +$balance _add;7 $data=Array(' Balance ' =$balance);8 $result=$model _member->edit ($user _id,$data); Writes to the database, returns a value indicating whether the write succeeded9 if($result) {Ten EchoJson_encode (Array(' result ' =>1, ' balance ' =$balance,)); Outgoing two parameters one}
Ecmall exercise 2: Passing data using Jquery:getjson