ajax在ecshop上的运用
ajax在 ecshop 上的运用主要分为步骤:
1.编写调用函数:
function query()
{
var sn_id = document.getElementById('sn_id').value.replace(/(^\s*)|(\s*$)/g, "");
if(!have_chinies(sn_id))
Ajax.call('sn_id.php?sn_id=' + sn_id, '', rep_sn_id, 'GET', 'JSON');
}
2.返回前台掉用:
<?php define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php'); include('includes/cls_json.php');
$json = new JSON; $result = array('goods_name' =>'没有找到任何记录' , 'goods_sn' => '没有找到任何记录'); $sn_id = !empty($_GET['sn_id'])?$_GET['sn_id']:''; $sql = "select goods_name,goods_sn from" . $ecs->table('goods') . "where (goods_id='$sn_id' or goods_sn='$sn_id') "; $res = $db->getAll($sql); if(!empty($res)) { $result['goods_name'] = $res[0]['goods_name']; $result['goods_sn'] = $res[0]['goods_sn']; } die($json->encode($result));
?>
3.执行回调函数:
function rep_sn_id(result) { document.getElementById('_good_id').innerHTML = '商品名称:' + result.goods_name + "</br>" document.getElementById('_good_id').innerHTML += '商品编号:' + result.goods_sn + "</br>";
}