I finally overcame the problem of passing full utf-8 strings from javascript to python, but now the carriage return "\n" which is present on the Javascript side is missing when the string is received in python. Is there something I’m supposed to do to achieve this?
function saveMeetingComments(){
var komments = $('#cmt_t').val()
var d = new Date();
var commentsText = $('#cmt_t').val()
var abc = ''
var request = par_makeHttpObject();
commentsText = stringTranslate(commentsText,"'",'`');
request.open("POST", "saveMeetingNote?clientID="+clid_+
"&co_ID="+coid_+
"&msgDate="+dateFormat(d, "dddd, mmmm dS, yyyy, h:MM TT")+
"&MeetType="+AGM_+
"&MeetDate="+meetdate+"-"+
"&Comments="+commentsText , false);
request.send();
$('#cmt_t').val('');
parkAll();
}
Comments is the only variable which may have carriage returns. On the Python side the code is as follows:
def saveMeetingNote(self, **kwargs):
clientID = kwargs['clientID']
co_ID = kwargs['co_ID']
MessageDate = kwargs['msgDate']
MeetingType = kwargs['MeetType']
MeetingDate = kwargs['MeetDate']
Comments_ = kwargs['Comments']
coName = dennislib.CompanyCoID2NAME(co_ID)[0]['FName']
ret = dennislib.saveMeetingNotes(clientID,co_ID,MessageDate,MeetingType,MeetingDate,Comments_,coName)
return
saveMeetingNote.exposed = True
Inspecting Comments_ shows that the \n are all gone…
TIA
Dennis
Looks like you’re not URL-encoding the data before sticking it in the POST request URL. Newlines aren’t the only thing which could be lost. What happens when someone types an
&in the comment field?Use
encodeURIComponentto fix this:On the server side, to decode this use: