zoukankan      html  css  js  c++  java
  • MVC收藏店铺


    @{
    ViewBag.Title = "GoodsInfoDetailIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
    }
    <h2>GoodsInfoDetailIndex</h2>
    <script>
    var GId = "";
    $(function () {
    GId = this.location.search.split("?")[1].split("=")[1];
    DataBound();
    })
    function DataBound() {
    $.ajax({
    url: "http://localhost:57190/api/Sale/GetGoodsInfos",
    data: { GId: GId },
    type: "get",
    dataType: "json",
    success: function (d) {
    $(d).each(function (i, n) {
    $("#GImg").attr("src", "http://localhost:57190" + n.GImg);
    $("#GName").text(n.GName);
    $("#GNum").text(n.GNum);
    $("#SName").text(n.SName);
    $("input:hidden[id='SId']").val(n.SId)
    })
    }
    })
    }
    //收藏宝贝
    function Goodcollect() {
    //判断是否登录
    if (getCookie("UsersInfo") == null) {
    this.location.href = '/Sale/LoginIndex';
    }
    else {
    var list = JSON.parse(getCookie("UsersInfo"));
    UId = list[0].UId;
    $.ajax({
    url: "http://localhost:57190/api/Sale/DecideGoodsCollect",
    data: { UId: UId, GId: GId },
    type: "get",
    dataType: "json",
    success: function (d) {
    if (d > 0) {
    var obj = {
    GId: GId,
    UId: UId,
    CGState: 0
    }
    $.ajax({
    url: "http://localhost:57190/api/Sale/AddGoodsCollectInfo",
    data: obj,
    type: "post",
    dataType: "json",
    success: function (d) {
    if (d > 0) {
    alert('收藏宝贝成功');
    $("#Goodcollect").attr("display", "display");
    }
    else {
    alert('收藏失败');
    }
    }
    })
    }
    else {
    alert('已收藏过此商品');
    }
    }
    })

    }

    }
    function Storecollect() {
    //判断是否登录
    if (getCookie("UsersInfo") == null) {
    this.location.href = '/Sale/LoginIndex';
    }
    else {
    var list = JSON.parse(getCookie("UsersInfo"));
    UId = list[0].UId;
    $.ajax({
    url: "http://localhost:57190/api/Sale/DecideStoreCollect",
    data: { UId: UId, SId: $("input:hidden[id='SId']").val() },
    type: "get",
    dataType: "json",
    success: function (d) {
    if (d > 0) {
    var obj = {
    SId: $("input:hidden[id='SId']").val(),
    UId: UId,
    CState: 0
    }
    $.ajax({
    url: "http://localhost:57190/api/Sale/AddStroesCollectInfo",
    data: obj,
    type: "post",
    dataType: "json",
    success: function (d) {
    if (d > 0) {
    alert('收藏店铺成功');
    $("#Storecollect").attr("display", "display");
    }
    else {
    alert('收藏失败');
    }
    }
    })
    }
    else {
    alert('已收藏过此店铺');
    }
    }

    })
    }
    }
    /* cookie中存值
    */
    function setCookie(name, value) {
    if (value) {
    var days = 1; //定义一天
    var exp = new Date();
    exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
    // 写入Cookie, toGMTString将时间转换成字符串
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString;
    }
    };

    /**
    * cookie中取值
    * */
    function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); //匹配字段
    if (arr = document.cookie.match(reg)) {
    return unescape(arr[2]);
    } else {
    return null;
    }
    };
    </script>
    <div style=" 50%;height: 50%;float:left">
    <div style="float:left">
    <img id="GImg" width='100px' height='100px' />
    </div>
    <div style="float:left;margin-left:20px">
    <h3><lable id="GName"></lable></h3>
    <lable id="GNum"></lable><br />
    <lable id="SName"></lable><br />
    <input id="SId" type="hidden" />
    <input id="UId" type="hidden" />
    </div>
    </div>


    <div style=" 50%;height: 50%;float:right">
    <label>我的收藏:</label>
    <br />
    <a href="/Sale/GoodcollectIndex">收藏de宝贝</a>
    <a href="/Sale/StorecollectIndex">收藏de店铺</a>
    <br /><hr />
    <input id="Goodcollect" type="button" value="收藏宝贝" onclick="Goodcollect()" />
    <input id="Storecollect" type="button" value="收藏店铺" onclick="Storecollect()" />
    </div>

  • 相关阅读:
    PTA L2-023 图着色问题-前向星建图 团体程序设计天梯赛-练习集
    PTA L2-004 这是二叉搜索树吗?-判断是否是对一棵二叉搜索树或其镜像进行前序遍历的结果 团体程序设计天梯赛-练习集
    PTA L2-006 树的遍历-二叉树的后序遍历+中序遍历,输出层序遍历 团体程序设计天梯赛-练习集
    HDU1166敌兵布阵(线段树单点更新)
    洛谷P1019——单词接龙(DFS暴力搜索)
    洛谷P1309——迷宫(傻瓜DFS)
    CodeForce-791B Bear and Friendship Condition(并查集)
    傻子都能懂的并查集题解——HDU1232畅通工程
    洛谷P1309——瑞士轮(归并排序)
    洛谷P1583——魔法照片(结构体排序)
  • 原文地址:https://www.cnblogs.com/zhang0405/p/13275509.html
Copyright © 2011-2022 走看看