Prototype Ajax Urlencode
Posted: Wed Mar 28, 2007 9:43 pm
I am having trouble using prototype to send an ajax request. I have a textarea that needs to have newlines in it but for some reason when i decode the value in php, it will not store in the database. Here is mycode:
here is the function that will be called from the ajax request:
Code: Select all
function leaveNote() {
var note = escape(el('leavenote').value);
var to = el('tid').value;
var from = el('fid').value;
var node = el('mynotes');
new Ajax.Updater('mynotes', 'inc/ajax.php',
{
method:'post',
parameters: {f: 'leaveNote', message: note, tid: to, fid: from},
onComplete: function(transport){
node.removeChild(node.childNodes[5]);
},
onFailure: function(){ alert('Unable to leave note.') },
insertion: Insertion.Top
});
return false;
}
Code: Select all
function leaveNote() {
$timestamp = time();
$_POST['message'] = urldecode($_POST['message']);
$q = "INSERT INTO notes (tid, fid, message, created) VALUES('$_POST[tid]', '$_POST[fid]', '$_POST[message]', '$timestamp')";
$GLOBALS['db']->query($q);
$u = new user();
$noteInfo = $u->getInfo('name, pic_xs', $_POST['fid']);
$noteInfo = $noteInfo[0];
if(empty($noteInfo['pic_xs'])) $noteInfo['pic_xs'] = 'img/nopicxs.gif';
echo '<div><a href="profile.php?id='.$_POST['fid'].'" class="cover"><img src="'.$noteInfo['pic_xs'].'" /><h4>'.$noteInfo['name'].'</h4>'.date('m/j/y H:i', $timestamp).'<br />'.$_POST['message'].'</a><br clear="all"></div>';
}
if(function_exists($_POST['f'])) $_POST['f']();