ECSHOP实验AJAX传值

来源:互联网 发布:沈阳淘宝网店推广 编辑:程序博客网 时间:2024/05/19 04:25

笔者先在ECSHOP首页模板增加了一段标签(flower.php为测试的php页面,相应的模板文件为flower.dwt)

<a href="http://localhost/flower.php">测试页面</a>


在flower.dwt页面写入

<!DOCTYPE html><html><head><meta charset="utf-8" /><title>测试的</title>{insert_scripts files='transport.js'}<script type="text/javascript">function textaaa(){if(document.getElementById('test')){var rec_id=document.getElementById('test').value;        Ajax.call('flower.php?act=ajax', 'rec_id=' + rec_id, textres, 'GET','JSON'); }}function textres(result){alert(result.content);}</script></head><body><input type="text" id="test" /><input type="button"  onclick="textaaa()"/></body></html>

相应的flower.php页面写入

define('IN_ECTOUCH', true);require(dirname(__FILE__) . '/include/init.php');require(ROOT_PATH . 'include/lib_order.php');require_once(ROOT_PATH .'include/cls_json.php');if ($_REQUEST['act'] == 'ajax')   {       $keywords = json_str_iconv(trim($_GET['rec_id']));          $keywords= $keywords+1;       $json = new JSON;    $result = array('error' => 0, 'message' => '', 'content' => $keywords);    die($json->encode($result));  }$smarty->display('flower.dwt');

即可

0 0
原创粉丝点击