Ecmall exercise 2: Passing data using Jquery:getjson

Source: Internet
Author: User

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>


<Table><TR><TD>Increase Balance:&nbsp;<inputtype= "text"OnBlur= "add_balance (this, ' {$info. user_id} ');"size= "ten"maxlength= "5"value= "0"></TD><TD>Increase Quantity:<spanID= "test">&nbsp;</span></TD></TR>

<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>

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.