In the previous chapter, we talked about how ecshop adds new fields to products-Lecture 7. In this chapter, we will combine some common use rules of ecshop. To talk aboutHow to call Ajax in ecshop. Ecshop secondary development process. We often encounter the problem of asynchronous Ajax.
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 ('includes/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 ));
The preceding section briefly introduces the simple rules used by Ajax in ecshop.