创建商品一直报错404

来源:4-3 商品模型模型--商品创建03

printf_HelloWorld

2019-04-20 13:42

https://img4.mukewang.com/5cbadf23000133ef06780575.jpg

https://img2.mukewang.com/5cbadf230001bb9410720336.jpg

这是我的前端代码

<html>
<head>
<meta charset="UTF-8">
    <link href="static/assets/global/plugins/bootstrap/css/bootstrap.min.css" style="stylesheet" type="text/css"/>
    <link href="static/assets/global/css/components.css" rel="stylesheet" type="text/css"/>
    <link href="static/assets/admin/pages/css/login.css" rel="stylesheet" type="text/css"/>
    <script src="static/assets/global/plugins/jquery-1.11.0.min.js" type="text/javascript"></script>
</head>

<body class="login">
    <div class="content">
        <h3 class="form-title">创建商品</h3>
        <div class="form-group">
            <label class="control-label">商品名</label>
            <div>
                <input class="form-control" type="text" name="title" id="title"/>
            </div>
        </div>
      <div class="form-group">
            <label class="control-label">商品描述</label>
            <div>
                <input class="form-control" type="text" name="description" id="description"/>
            </div>
        </div>
      <div class="form-group">
            <label class="control-label">价格</label>
            <div>
                <input class="form-control" type="text" name="price" id="price"/>
            </div>
        </div>
      <div class="form-group">
            <label class="control-label">图片</label>
            <div>
                <input class="form-control" type="text" name="imgUrl" id="imgUrl"/>
            </div>
        </div>
      <div class="form-group">
            <label class="control-label">库存</label>
            <div>
                <input class="form-control" type="text" name="stock" id="stock"/>
            </div>
        </div>

        <div class="form-actions">
            <button class="btn blue" id="create" type="submit">
                提交创建
            </button>
        </div>
    </div>
</body>
<script>
    jQuery(document).ready(function () {

        $("#create").on("click",function(){
            var title = $("#title").val();
            var description = $("#description").val();
            var price = $("#price").val();
            var imgUrl = $("#imgUrl").val();
            var stock = $("#stock").val();

            if(title == null || title ==""){
                alert("商品名不能为空");
                return false;
            }
         if(description == null || description ==""){
                alert("描述不能为空");
                return false;
            }
         if(imgUrl == null || imgUrl ==""){
                alert("图片链接不能为空");
                return false;
            }
         if(stock == null || stock ==""){
                alert("库存不能为空");
                return false;
            }
            $.ajax({
                type:"POST",
                datatype:'json',
                contendType:"application/x-www-form-urlencoded",
                url:"http://localhost:8090/user/create",
                data:JSON.stringify({
               "title":title,
               "description":description,
               "price":price,
               "imgUrl":imgUrl,
               "stock":stock
                }),
            xhrFields:{withCredentials:true},
                success:function (data) {
                    if(data.status ==  "success"){
                        alert("创建成功");
                    }
                    else{
                        alert("创建失败1,原因为"+data.data.errMsg)
                    }
                },
                error:function (data) {
                    alert("创建失败2,原因为"+data.responseText);                  
                }
            })
        })
        return false;
    });
</script>


</html>

犯了很蠢的错误,链接写错了,应该是localhost:8090/item/create,我给写成了localhost:8090/user/create

简直蠢驴!!

写回答 关注

1回答

  • 范子祺
    2019-08-16 21:03:47

    新手日常-------

SpringBoot构建电商基础秒杀项目

应用SpringBoot快速搭建拥有用户、商品、交易及秒杀活动的电商秒杀应用。

49064 学习 · 954 问题

查看课程

相似问题