How Ajax is called in ecshop-lecture 8

Source: Internet
Author: User

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.

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: info-contact@alibabacloud.com 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.