Use [ecshop] For Ajax. Call in ecshop

Source: Internet
Author: User
Ajax in ecshop is very easy to use. It is also very difficult to use for the first time. When I use more, I feel very simple and convenient.

First, create a dwt. write a form in it, add a form to submit the time.

Second, add a function in Js.

Function sub_zixun () {var FRM = document. forms ['zixun _ form']; var msg_title = FRM. elements ['msg _ title']. value; var msg_phone = FRM. elements ['msg _ phone']. value; var user_email = FRM. elements ['user _ email ']. value; var msg_content = FRM. elements ['msg _ content']. value; var MSG = ''; If (msg_title.length = 0) {MSG + = 'title cannot be blank '+' \ n';} If (msg_phone.length = 0) {MSG + = 'phone number cannot be blank '+' \ n';} If (user_emai L. length = 0) {MSG + = 'email cannot be blank '+' \ n';} If (msg_content.length = 0) {MSG + = 'comment cannot be blank '+' \ n';} If (MSG. length> 0) {alert (MSG); Return false;} else {Ajax. call ('zixun. PHP? Act = act_sub, 'msg _ phone = '+ msg_phone +' & user_email = '+ user_email +' & msg_content = '+ msg_content +' & msg_title = '+ msg_title, act_callback, 'post', 'text', true, true );}}

3: added the callback function act_callback ()

Function act_callback (result) {If (result = 'true') {alert ("comments submitted successfully");} else {alert ("comments submitted failed ");}}

Processing Ajax callback value results

Elseif ($ act = 'act _ Sub ') {include_once (root_path. 'regiondes/lib_clips.php'); $ message = array ('user _ id' =>$ _ session ['user _ id'], 'User _ name' => $ _ session ['user _ name'], 'user _ email '=> isset ($ _ post ['user _ email'])? Htmlspecialchars (TRIM ($ _ post ['user _ email ']): '', 'msg _ type' => isset ($ _ post ['msg _ type'])? Intval ($ _ post ['msg _ type']): 0, 'msg _ title' => isset ($ _ post ['msg _ title'])? Trim ($ _ post ['msg _ title']): '', 'msg _ content' => isset ($ _ post ['msg _ content'])? Trim ($ _ post ['msg _ content']): '', 'order _ id' => 0, 'msg _ region' => 1, 'msg _ phone' => trim ($ _ post ['msg _ phone']), 'upload' => array ()); // If (add_message ($ message) {echo 'true';} else {echo 'false ';}}

In this way, all the Ajax call steps in ecshop are completed.

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.