fix for backslashes in data not encoding correctly

when posting data that contains backslashes such as "\\foo\nbar", it is not encoded correctly.
To fix this, I used JSON.stringify to create a valid string and then remove the first and last ticks with slice(1,-1), then perform your tick escape code.