I am trying to send a from’s content over AJAX POST request, using jquery. Server is nodeJS built. My problem occurs when I sent a multilne message:
line1
line2
line3
becomes
line1,line2,,line3
On the server. This is the client side javascript/jquery code:
function send() {
var dataString = 'to=' + $("#to").val() + '&subject=' + $("#subject").val() + '&body=' + $("#body").val();
$.ajax({
type: "POST",
url: "/sendMail",
cache: false,
data: dataString,
success: function(data) {
location.reload();
},
error: function(xhr, textStatus, errorThrown) {
location.reload();
}
});
}
Then on the server side I have
var send = {call: function (request, response, params) {
var subject = request.parameters['subject'];
var body = request.parameters['body'];
console.log(body);
response.end();
}
};
I wrote Request and Response, but they work ok – I get the right post parameters.
What could be the problem then?
AJAX sends the data in one request string, You may use multiple request parameters (one for each line) or use some other format, like JSON. It could go like this :