简体   繁体   中英

Ajax:unable to POST (404)

POST Script in manage.ejs file i console logged the data its working there and

<script type="text/javascript">
  var guildID = "<%= guild.id %>";
  let data = {some valid json}
  $('.btn-primary.btn').click(function() {
            $.ajax({
                url: `/dashboard/${guildID}/manage/save`,
                type: "POST",
                dataType: "json",
                data: JSON.stringify(data),
                contentType: "application/json",
                cache: false,
                timeout: 5000,
                complete: function() {
                  //called when complete
                  console.log('process complete');
                },

                success: function(data) {
                  console.log(data);
                  console.log('process sucess');
               }
              });
        })
</script>

dashboard.js i imported the body-parser am i missing something in /save other all post are working too

 var bodyParser = require("body-parser");
  app.use(bodyParser.json());       // to support JSON-encoded bodies
  app.use(bodyParser.urlencoded({     // to support URL-encoded bodies
    extended: true
  })); 

app.get("/dashboard/:guildID/save", checkAuth, async (req, res) => {
    const guild = client.guilds.get(req.params.guildID);
    if (!guild) return res.status(404);
    res.contentType('json');
   console.log(req.body)

    res.redirect("/dashboard/"+req.params.guildID);
  });

您发布到: /dashboard/${guildID}**/manage/save**但服务在端点/dashboard/:guildID**/save**

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM