Hello. Mongoose is new to me, and I’m trying to learn it bit by bit, but I came across a problem stated below.
- My goal is: To receive user input data from webpage then print it in console.
- My actions are: I used the simplest_web_server then added a few bits of code such as
mg_register_http_endpoint(nc,"/post_ID",handle_post_ID)
then used the sample for the code above:
static void handle_post_ID(struct mg_connection *nc, int ev, void *ev_data) {
(void) ev; (void) ev_data;
mg_printf(nc, "HTTP/1.0 200 OK\r\n\r\n[I am Hello1]");
nc->flags |= MG_F_SEND_AND_CLOSE;
}
just to see how it really works.
for my JS code:
var myUrl = "/post_ID",
devID = '',
inputID = $('#inputID'),
outputID = $('#outputID');
$(document).on('submit', function (e) {
e.preventDefault();
devID = inputID.val(); // get the value of input
$.ajax({
type: "POST",
url: myUrl,
data: devID,
processData: false,
contentType: false,
cache: false,
success: function (d) {
console.log("Data: "+d);
outputID.html(devID); // display value of devID
}
});
});
- The result I see is:
POST http://localhost:8053/post_ID 404 (Not Found)
send @ jquery.min.js:2
ajax @ jquery.min.js:2
(anonymous) @ jqmain.js:11
dispatch @ jquery.min.js:2
v.handle @ jquery.min.js:2
I was expecting to see the message of the handler but it says 404 not found.
I don’t know the cause of this problem as I’m currently learning about mongoose.
Also I only attached the header and source files of mongoose as stated in their instructions on Github.
Any help or clue is greatly appreciated.
Thank you.