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.