Page 1 of 1

sending post parameters using ajax

Posted: Sun Jul 08, 2007 12:14 pm
by s.dot
This seems a bit barbaric to me, but since ajax, as a congregated technology, is fairly new, it may be the only/best way to send post parameters. By turning them into a looooooooong query string.

Like the following I'm using for a wysiwyg editor type thing.

Code: Select all

function getParams()
{
	var docform = document.ddlform;
	var params = 'list=';
	params += encodeURIComponent(docform.list.value);
	params += '&list_text_size=';
	params += encodeURIComponent(docform.list_text_size.value);
	params += '&list_text_color=';
	params += encodeURIComponent(docform.list_text_color.value);
	params += '&list_text_font=';
	params += encodeURIComponent(docform.list_text_font.value);
	params += '&list_text_bold=';
	params += docform.list_text_bold.checked;
	params += '&list_text_italics=';
	params += docform.list_text_italics.checked;
	params += '&list_text_underline=';
	params += docform.list_text_underline.checked;
	params += '&list_text_overline=';
	params += docform.list_text_overline.checked;
	params += '&list_text_linethrough=';
	params += docform.list_text_linethrough.checked;
	params += '&list_text_ls=';
	params += encodeURIComponent(docform.list_text_ls.value);
	params += '&list_text_ws=';
	params += encodeURIComponent(docform.list_text_ws.value);
	params += '&list_sort=';
	params += encodeURIComponent(getCheckedValue(docform.list_sort));
	params += '&list_bgcolor=';
	params += encodeURIComponent(docform.list_bgcolor.value);
	params += '&list_border_style=';
	params += encodeURIComponent(docform.list_border_style.value);
	params += '&list_border_width=';
	params += encodeURIComponent(docform.list_border_width.value);
	params += '&list_border_color=';
	params += encodeURIComponent(docform.list_border_color.value);
	return params;
}
I may be asking a stupid question, but is there a js function to "implode" upon all form elements? Rather than manually building a long query string that is very prone to errors.

Posted: Mon Jul 09, 2007 6:24 am
by Gente
Maybe this thread can help you - viewtopic.php?t=70134