Prototype Ajax Urlencode

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Prototype Ajax Urlencode

Post by chris12295 »

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:

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;
}
here is the function that will be called from the ajax request:

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']();
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Have you checked to see if the data being entered into the DB has line feeds? Why not check it every step of the way so you can find where the LF's are being removed?
chris12295
Forum Contributor
Posts: 113
Joined: Sun Jun 09, 2002 10:28 pm
Location: USA
Contact:

Post by chris12295 »

Well its not that the data is stored without the line feeds, its that it will not store any data at all in the database.
Post Reply