1: first, how does ecshop define Ajax objects.
The Ajax objects in ecshop are defined in the JS/transport. js file. It contains an Ajax object file. Declared a var Ajax = transport; object and a method Ajax. Call = transport. Run;
2: In ecshop, AJAX can transmit data in two ways: Get and post.
Ajax. Call ('user. php? Act = is_registered ', 'username =' + username, registed_callback, 'get', 'text', true, true );
Ajax. Call ('user. php? Act = return_to_cart ', 'order _ id =' + orderid, returntocartresponse, 'post', 'json ');
3: Ajax in ecshop can be a Text object or a JSON object. For example, the following code
Goods. Quick = quick;
Goods. spec = spec_arr;
Goods. goods_id = goodsid;
Goods. Number = number;
Goods. Parent = (typeof (parentid) = "undefined ")? 0: parseint (parentid );
Ajax. Call ('flow. php? Step = add_to_cart ', 'goods =' + goods. tojsonstring (), addtocartresponse, 'post', 'json ');
Goods is an object, and it is transmitted by JSON. The returned result is also an object.
4: In the ecshop Ajax function, the third parameter is the function name. For example, the above Code addtocartresponse is the callback function for Ajax processing results.
5: In the PHP code of ecshop, the function is generally accepted through the get or POST method. For example, in the following example, an object is accepted. JSON data format is also required for processing. For example:
Include_once ('des/cls_json.php ');
$ _ Post ['goods '] = json_str_iconv ($ _ post ['goods']);
The returned results also need to be sent to JS in JSON format
Die ($ JSON-> encode ($ result ));
For example:
Html
<input type="button" name="search" value="{$lang.button_search}" onclick="searchUser();" /><select name="user_search[]" id="user_search" size="15" style="width:260px" ondblclick="addUser()" multiple="true"> </select>
/*** Search user by user name */function searchuser () {var eles = document. forms ['theform']. elements;/* fill list */var KEYWORDS = utils. trim (eles ['keyword']. value); If (keywords! = '') {Ajax. Call ('bonus. php? Is_ajax = 1 & act = search_users ', 'keywords =' + keywords, searchuserresponse, "get", "JSON") ;}} function searchuserresponse (result) {var eles = document. forms ['theform']. elements; eles ['user _ search [] ']. length = 0; If (result. error = 0) {for (I = 0; I <result. content. length; I ++) {var opt = document. createelement ('option'); OPT. value = result. content [I]. user_id; OPT. TEXT = result. content [I]. user_name; eles ['user _ search [] ']. options. add (OPT );}}}
PHP code
/* Users * // -- Search user/* ------------------------------------------------------ */if ($ _ request ['ac'] = 'search _ users ') {$ KEYWORDS = json_str_iconv (TRIM ($ _ Get ['keyword']); $ SQL = "select user_id, user_name from ". $ ECs-> table ('users '). "Where user_name like '% ". mysql_like_quote ($ keywords ). "% 'or user_id like' % ". mysql_like_quote ($ keywords ). "% '"; $ ROW = $ db-> getall ($ SQL); make_json_result ($ row );}