That's my app. When I try to open ip/delete I get an error
Cannot GET /delete
I'm following this tutorial, https://www.tutorialspoint.com/nodejs/nodejs_express_framework.htm
var express = require('express');
var app = express();
app.use(express.static('public'));
app.get('/', function(req, res) {
console.log("Got a GET request");
res.send('GBArena Labs');
})
app.post('/', function(req, res) {
console.log("Got a POST request");
})
app.delete('/delete', function(req, res) {
res.send('Delete');
console.log("Got a DELTE request");
})
app.listen(8081);
You can't navigate to a DELETE. You have to send a DELETE request. In example :
<a href="/delete">My delete link<a/>
will be sent as a GET request and not a DELETE.
In order to hit your delete endpoint, you would have to use a ajax library like jquery $.ajax and using
$.ajax({
url: '/delete',
type: 'DELETE',
success: function(result) {
// Do something with the result
}
});
from the client side.
There are many ways, but i would suggest you looking into : HTTP verbs
您可能需要在没有/ delete的情况下调用路由,并使用REST客户端(例如Fiddler或Postman)的HTTP动词DELETE。
First, you try to access by ip/delete
endpoint. I assume you will get an error because you are not using the port of the application (you have to access by ip:port/delete)
You have to know about the usage of DELETE method. When you try to directly access the ip/delete
endpoint, your browser will set it as GET method while in your application, there is not GET method for ip/delete
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.