jQuery Appending unwanted data
Some jQuery function in my code is inserting the string:
jQuery15206649508478338135_1314906667378
into user-provided feedback. This is 开发者_开发技巧happening from multiple forms and it's getting stored in the database, which is really annoying our users. One sample of such code:
$(".sendFeedback").live("click", function() {
var feedbackText = $(".feedbackText:visible").val();
var errorElement = $(".feedbackError:first");
if (isEmptyTrimmed(feedbackText)) {
errorOut(errorElement, language.pleaseEnterFeedbackText);
return false;
}
var sendFeedback = { email : userSettings.email, firstName : "",lastName : "",primaryRole : "", description : "<br />Feedback text: <pre>" + feedbackText + "</pre>",
sendNotification : false, isPartner : false , formType : 3};
callService("sendFeedback", sendFeedback);
currentMessage = language.thankYouForTheFeedback;
loadScreenByHash("mainScreen");
});
function callService(serviceName, data, callbackFunction) {
var json = $.toJSON(data);
json = "{ " + serviceName + ": " + json + " }";
$.post(serviceUrl, json,
function(response) {
if (callbackFunction) {
callbackFunction(response);
}
}, 'json').error(function() {
if (callbackFunction) {
callbackFunction();
}
});
}
The callService function directs to a Java server, so I'm doubting it's getting inserted there. The java server writes to the DB, so I'm pretty sure it's getting inserted in the javascript code.
It happens other places as well, and they follow the same formula: read user input with .val(), pass to callService (sometimes through additional JS function). A sample of the output data:
I created a quiz but can not figure out how to run it for my class. there are no buttons that say run quizjQuery15206649508478338135_1314906667378? Customer Name
I've also seen it appended at the end of a string. Let me know if anyone has seen this before.
I found the cause of the problem. User data was entered, sent to the database, but the database was not set for UTF-8. The problem occurred every time the character encoding was messed up in the database. When the database returned garbage, it would trigger the string to be added.
Changing the database encoding solved this problem.
精彩评论