doumen5087 2015-08-10 08:53
浏览 36
已采纳

CS-Cart Ajax对div的响应

CS-Cart ajax is working fine, I am also getting response but how can I use this response with html/js on my view(checkout.tpl) file.

Controller (front-end) : send_sms.php

use Tygh\Registry;
use Services_Twilio;
use Tygh\Ajax;

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

 if ($mode == 'send_sms') {

    $status = 1;
    $response = array(
        'status' =>$status,
        'data' =>'Hello World',
    );

   if($status == 1) {
        fn_set_notification('N', fn_get_lang_var('success'), fn_get_lang_var('sms_sent'), true);
    } else {
        fn_set_notification('E', fn_get_lang_var('warning'), fn_get_lang_var('sms_failed'), true);

    }

    $val=json_encode($response);

    Registry::get('ajax')->assign('result', $val);

 }
 exit;
}

View checkout.tpl (design/themes/responsive/templates/views/checkout/checkout.tpl)

<div id="result">
    <!-- id="result" -->
    <!-- result -->
</div>
<h2>Verify your number</h2>

<form class="cm-ajax" action="index.php" method="post" name="send_sms">


    <input type="hidden" name="result_ids" value="result" />

    <div class="form-control send_sms_block">
        <input type="text" name="country_code" id="country_code" disabled value="+92"/>
        <input type="text" name="carrier_code" id="carrier_code" disabled value="300"/>
        <i class="ty-icon-down-micro open_cr"></i>
        <input type="text" name="phone" id="phone"/>

        <div class="carrier_list hidden">
            <ul>
                <li>301</li>
                <li>302</li>
            </ul>
        </div>
    </div>
    <div class="clearfix"></div>
    <input class="ty-btn ty-btn__big" id="send_sms" type="submit" value="Send Pin" name="dispatch[send_sms.send_sms]"/>
</form>

</div>
  • 写回答

2条回答 默认 最新

  • dtwupu6414 2015-08-11 15:51
    关注

    Please try the following solution:

    php file:

    use Tygh\Registry;
    use Services_Twilio;
    use Tygh\Ajax;
    
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    
     if ($mode == 'send_sms') {
    
        $status = 1;
        $response = array(
            'status' =>$status,
            'data' =>'Hello World',
        );
    
       if($status == 1) {
            fn_set_notification('N', fn_get_lang_var('success'), fn_get_lang_var('sms_sent'), true);
        } else {
            fn_set_notification('E', fn_get_lang_var('warning'), fn_get_lang_var('sms_failed'), true);
    
        }
    
        $val=json_encode($response);
    
        Registry::get('view')->assign('result', $val);
        Registry::get('view')->display('views/path/to/tpl/file.tpl');
     }
     exit;
    }
    

    tpl file:

    <div id="result">
    {if $result}{$result}{/if}
    <!--result--></div>
    
    <h2>Verify your number</h2>
    
    <form class="cm-ajax" action="index.php" method="post" name="send_sms">
    
    
        <input type="hidden" name="result_ids" value="result" />
    
        <div class="form-control send_sms_block">
            <input type="text" name="country_code" id="country_code" disabled value="+92"/>
            <input type="text" name="carrier_code" id="carrier_code" disabled value="300"/>
            <i class="ty-icon-down-micro open_cr"></i>
            <input type="text" name="phone" id="phone"/>
    
            <div class="carrier_list hidden">
                <ul>
                    <li>301</li>
                    <li>302</li>
                </ul>
            </div>
        </div>
        <div class="clearfix"></div>
        <input class="ty-btn ty-btn__big" id="send_sms" type="submit" value="Send Pin" name="dispatch[send_sms.send_sms]"/>
    </form>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度