/**
*收藏商品
*/
function collect(url)
{
alert(url);
$.get(
url,
function(data)
{
//var res = JSON.parse(data);--亦可
var res = eval("(" + data + ")");
alert(res.msg);
var url2 = "<?php echo U('Home/Product/del_collect',array('member_id'=>$userinfo['id'],'product_id'=>$product['id'],'store_id'=>$product['store_id'])); ?>";
var func = "del_collect('" + url2 + "')";
$("#collect").attr("onclick",func);
//var img = $("#collect").find("img").attr("src");
var img = $("#collect_icon_yes").val();
//alert(img);
var html = "<img src='" + img + "' id='collect_icon' width='20' class='vertical' style='margin-top:-5px;' />已经收藏";
$("#collect").html(html);
}
);
}
这段代码中,有几点需要注意:
1.JSON.parse(json)
在JS中,它可以解析json。eval也可以。
2.在ThinkPHP的tpl文件中,可以如此获得URL。
3.jquery的attr\find等方法,我要看文档才能使用。不熟练。