I have been using encodeURIComponent for that. But I'll do ya one better, here's part of the function I wrote and have been using for our Chrome to Notifo extension:
creds is just "username:apikey" that I did a creds.split(":") on earlier. i have the service event ("title") hardcoded in this function.
or - with formatting: http://gist.github.com/raw/564058/4df889c0dd4ddd10d338b09b6dfcb356da962543/gistfile1.txt
function sendNotifo(label,msg,uri) {
var https = new XMLHttpRequest();
var creds = localStorage.getItem("notifo");
var auth = "Basic " + Base64.encode(creds);
var push = 'to=' + encodeURIComponent(creds[0]) + '&msg=' + encodeURIComponent(msg) + '&uri=' + encodeURIComponent(uri) + '&label=' + encodeURIComponent(label) + '&title=' + encodeURIComponent("Page");
https.onreadystatechange = function() {
if (this.readyState == 4)
switch (https.status) {
case 200:
//Success do what you want here
break;
default:
// Error - JSON.parse(https.responseText)['response_message'];
break;
}
};
https.open('POST', 'https://api.notifo.com/v1/send_notification', true);
https.setRequestHeader('Authorization', auth);
https.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
https.send(push);
}
It looks like you're new here. If you want to get involved, click one of these buttons!