ecshop中ajax.call使用 [ECshop]

來源:互聯網
上載者:User
ecshop中的ajax非常好用,當自己第一次使用的時候,也非常吃力。當自己用多了的時候,卻感覺十分簡單,也特別方便。

首先,建立dwt.裡面寫個form進去,加個form提交時間的按扭<img src="images/tijiaoanniu_07.gif" width="69" height="20" border="0" style="cursor:pointer" onclick="return sub_zixun();" />

   其次,在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 += '標題不可為空' + '\n';   }   if (msg_phone.length == 0)   {msg += '電話號碼不可為空' + '\n';   }   if (user_email.length == 0)   {msg += 'Email不可為空' + '\n';   }    if (msg_content.length == 0)   {msg += '評論不可為空' + '\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:增加回呼函數act_callback ()

function act_callback(result){if(result == 'true'){alert("提交評論成功");}else{alert("提交評論失敗");}}

處理ajax回調值的結果

elseif ($act == 'act_sub'){include_once(ROOT_PATH . 'includes/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_area'    => 1,        'msg_phone'   => trim($_POST['msg_phone']),        'upload'      => array()     );//留言板提交的資料         if (add_message($message)){      echo 'true';     }else{      echo 'false';     }}

這樣就完成了一次ecshop中ajax的所有調用步驟。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.