I’m saving some data through the URL and one of these data elements is a text. I want to be able to save and store notes with hashtags on them. For example, I want to be able to save “I believe in #yolo”, but when I save it (through php), and retrieve it again with javascript, I get “I believe in”. Anyway, I can get that #yolo back? I tried using str_replace, but I may have gotten the regex wrong.
Thanks for all the help!
function dropsuccess() {
answerArray = [];
answerArray.id = Math.round(new Date().getTime() / 1000);
answerArray.text = document.getElementById("boglory").value;
$.getJSON("saveBlade.php?id="+answerArray.id+"&text="+answerArray.text,
function(data) {
if (data.hasOwnProperty("error")) {
alert(data.error);
} else {
$("#handle").animate({marginTop:"100%"},800,
function() {
document.getElementById("handle").style.display = "none";document.getElementById("bladecontainer").style.display = "none";$('#qod').fadeIn('medium');
});
}
});
}
answerArray.text includes the text that is being passed. Ex (“I believe in #yolo.”) #yolo is a string, not a div-id tag.
The problem is that
#is a reserved character in URLs to indicate a jump to an anchor.You need to escape it. JQuery automaticly escape all characters that need to if you supply them as the data argument in the getJSON function:
Look here for details