On the HTML side, when I press a button, the following is script is called:
$("form").submit(function(f) {
f.preventDefault();
$.ajax({
url: "/example",
data: "name=Mr_Skid_Marks",
type: "GET",
success: function(data) {
//do something with data
},
error: function(e) {
//bad news
}
});
});
On the node.js side, I am trying to retrieve the name field in the HTTP request handler:
var queryData = url.parse(req.url, true).query;
var nameVal = queryData.name;
response.setHeader('Content-Type', 'application/json');
response.end(JSON.stringify({name: nameVal}));
I able to retrieve the name field if the data is typed into the url, ie: localhost:1111/html_file.html?name=Mr_Skid_Marks
, but the problem is when I press the button I do not get the data in that format (the url is localhost:1111/html_file.html?
Any tips or links would be appreciated!