Prototype method: post example?


I’m currently using prototype in a user comments script to submit text to a database, however there is a limit on the amount of text that can be submitted via GET. I’d like to use method: “post”, but nothing I’ve tried has worked. I’m struggling…

my current javascript:

function ajax_test()
	var url = "test_ajax_functions.php";
	var data = "something=nothing";
	var target = 'output';
	function ajax_response(resp)
	var myAjax = new Ajax.Updater(
		{method: 'post', parameters: data, onComplete: ajax_response}

simple html

<form id="form1" name="form1" method="post" action="" enctype="application/x-www-form-urlencoded">
  <input type="text" id="text1" name="text1" value="nothing" />
  <input type="button" name="Submit" value="Submit" onclick="ajax_test();" />

simple php


prototype is working, and this function works passing the variables as URI variables, and changing the method to ‘get’.

what am I doing wrong?

many thanks for any assistance. :slight_smile:

forgot to mention; alert(resp.responseText); gives an empty popup, so it’s “completing”, only it seems that either my form data is not being sent, or I’m not properly intercepting it.

thanks again,

I’ve highlighted in red where I think you’re having the issue. Specifically, your options should be like this for a post:

var options = {
new Ajax.Request(url,options);

You can see that I’m using “postBody” instead of “parameters”. The post body is a set of name/value pairs separated by &, so make sure your values are escaped if there’s the potential for any odd characters.



this works nicely; thank you very kindly. :slight_smile: