ajax:
//获取商品属性数据
function initGoodsAttr(){
$.ajax({
type: ‘GET‘,
url:"<?php echo WX_SITE_URL.‘/wx_shop.php?act=goods&op=goods_info_json&id_type=‘.$output[‘id_type‘].‘&goods_id=‘.$output[‘goods_id‘];?>",
data:‘‘,
dataType: ‘json‘,
success: function(data){
if (data.statusCode == ‘200‘) {
goods = data.result;
initAttrPage(openid);
currentGoodsCount = 1;
}
},
error: function(xhr, type){
alert(‘商品属性获取失败!‘);
}
});
}
商城跳转:
啊屋童装
啊屋童装
微信执行请求的方法:
$appid = "";
$appsecret = "";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$jsoninfo = json_decode($output, true);
$access_token = $jsoninfo["access_token"];
weiPHP中持久层的代码:
if (! empty ( $_REQUEST [‘shop_id‘] )) {
$this->shop_id = I ( ‘shop_id‘ );
session ( ‘wap_shop_id‘, $this->shop_id );
} else {
$this->shop_id = session ( ‘wap_shop_id‘ );
}
$map [‘token‘] = get_token ();
后台json的解析:
app提交:
$raw_str = $GLOBALS[‘HTTP_RAW_POST_DATA‘];
$post = json_decode($raw_str);
$cate_id = intval($post->cate_id)>0 ? $post->cate_id : 0;//商品分类
Ajax提交:
(前)
var data = JSON.stringify(cart);
(后)
$str2 = file_get_contents("php://input");
$post = json_decode($str2);
$result = add_cart($post->member_id, $post->cart_all);
(前)
var data = {
"mobile_phone": username
};
(后)
$mobile_phone = $_POST[‘mobile_phone‘];
jquery操作html:
判断没有没有类:$(".product-subtract").hasClass("grey")
移除类:$(".product-subtract").removeClass("grey");
增加类:$(".product-subtract").addClass("grey");
内容获取:$(".attr-info").html();
内容赋值:$(".attr-info").html(color_value+","+ size_value);
获取属性值:var dbg = the_size.attr("data_belong_goods");// 取出当前size所从属的商品id
修改属性值:$("#spec_image").attr("src",good.spec_image);
元素后追加内容:$(‘.row‘).after(goods);
元素前追加内容:$(‘.row‘).before(goods);
内部后追加内容:$(‘.row‘).append(goods);
内部前追加内容:$(‘.row‘).prepend(goods);
移除:$("#div1").remove();
隐藏:$("#div1").hide();
显示:$("#div1").show();
页面刷新:location.reload();
返回上一页并刷新:location.href = document.referrer
返回上一页不刷新:window.history.go(-1);
选择到多个元素后到遍历:
$(".attr").each(function (){}
获取父节点:
var thisPlus = $(this);
var thisGrid = thisPlus.closest(‘._grid‘);
js类型转换
count =Number(clothe.goods_storage);
str =String(clothe.goods_name);
var obj = JSON.parse(str); //由JSON字符串转换为JSON对象
js数组:
var array = [];
array.push(temp_color);
空值判断:
if (openid.length == 0)
js价格计算:
var test = ‘1.11‘;
var test2 = ‘1.01‘;
alert((Number(test)-Number(test2)).toFixed(2));
js页面跳转:
window.location.href=‘<?php echo WX_SITE_URL.‘/wx_shop.php?act=member&op=loginPage‘?>‘;
js 使用post请求跳转页面的方法(将参数封装到一个form内);
$("#service").click(function () {
var data = {
"goods_id":"<?php echo $output[‘goods_info‘][‘goods_commonid‘]; ?>",
"isSingle":"0",
"goods_price": $(".member-price").html()
};
standardPost("<?php echo WX_SITE_URL.‘/wx_shop.php?act=goods&op=openim‘?>", data);
});
function standardPost (url,args)
{
var body = $(document.body),
form = $("<form method=‘post‘></form>"),
input;
form.attr({"action":url});
$.each(args,function(key,value){
input = $("<input type=‘hidden‘>");
input.attr({"name":key});
input.val(value);
form.append(input);
});
form.appendTo(document.body);
form.submit();
document.body.removeChild(form[0]);
}
//使用form提交数据。 带array
function standardPost (url,args){
var body = $(document.body),
form = $("<form method=‘post‘></form>"),
input;
form.attr({"action":url});
$.each(args,function(key,value){
if (Object.prototype.toString.call(value) === ‘[object Array]‘) {
for (var i = 0; i < value.length; i++) {
var name = key+"[]";
input = $("<input type=‘hidden‘>");
input.attr({"name":name});
input.val(value[i]);
form.append(input);
}
}else{
input = $("<input type=‘hidden‘>");
input.attr({"name":key});
input.val(value);
form.append(input);
}
});
form.appendTo(document.body);
alert($("form").html());
form.submit();
document.body.removeChild(form[0]);
}
php:
数组长度:count(array)
数组增加:array_push($a,"blue","yellow");
字符串相等:
if (strcasecmp($output[‘goods_info‘][‘return_price‘], ‘0.00‘)==0)
或恒等式:
if ($output[‘goods_info‘][‘return_price‘] ==="0.00")
类型转换:
$foo = "1"; // $foo 是字符串类型
$bar = intval($foo); // $bar 是整型
分割字符串:
$cart_id = explode(‘,‘, $_GET[‘cart_id‘]);
空值检查:
(!isset($mobile_phone) || empty($mobile_phone)
合成图片:
<?php
function mergerImg($imgs) {
list($max_width, $max_height) = getimagesize($imgs[‘dst‘]);
$dests = imagecreatetruecolor($max_width, $max_height);
$dst_im = imagecreatefrompng($imgs[‘dst‘]);
imagecopy($dests,$dst_im,0,0,0,0,$max_width,$max_height);
imagedestroy($dst_im);
$src_im = imagecreatefrompng($imgs[‘src‘]);
$src_info = getimagesize($imgs[‘src‘]);
imagecopy($dests,$src_im,0,$max_height/2,0,0,$src_info[0],$src_info[1]);
imagedestroy($src_im);
header("Content-type: image/jpeg");
imagejpeg($dests);
}
$imgs = array(
);
<?php echo WX_TEMPLATES_URL;?>/