http doesn't parse xmlhttprequest form encoded

44 views
Skip to first unread message

Andrew Oliver

unread,
Apr 18, 2013, 4:40:52 PM4/18/13
to ceylon...@googlegroups.com
This works in ceylon:

<form action="contacts" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" />
<label for="address">Address:</label>
<textarea rows="5" cols="40" id="address" name="address" ></textarea>
<label for="phone">Phone:</label>
<input type="text" id="phone" name="phone" />
<label for="email">Email:</label>
<input type="text" id="email" name="email" />

<input type="submit" name="sumbit"/>
</form>

I can do request.parameters("name") and everything works as expected...


This does not work in ceylon (But does in other languages):

<form>
<label for="frmName">Name:</label>
<input type="text" id="frmName" name="frmName" />
<label for="frmAddress">Address:</label>
<textarea rows="5" cols="40" id="frmAddress" name="frmAddress" ></textarea>
<label for="frmPhone">Phone:</label>
<input type="text" id="frmPhone" name="frmPhone" />
<label for="frmEmail">Email:</label>
<input type="text" id="frmEmail" name="frmEmail" />
<button onclick="saveContact(); return false;" >Save</button>
</form>

with associated jquery: 

var saveContact = function(){
clearNotices();
var strId = $("#frmContacts").find(":selected").val();
var strName = $("#frmName").val();
if((strName == "")||(strName.search(/\S/) == -1)){
notice("A name is required to save a new contact.");
return;
}
var strAddress = $("#frmAddress").val();
var strPhone = $("#frmPhone").val();
var strEmail = $("#frmEmail").val();
if(strId == "-1"){//new
var url = "/contacts/";
$.post(url, 
{ 'utf8':"✓", 'authenticity_token': "lJxO7oZQ460Rw3+4bk/aO9kpKhdO3+bUFmt+cByPsC8=", 
'contact[name]': strName, 'contact[address]': strAddress,
'contact[phone]': strPhone, 'contact[email]': strEmail },
function(data){
retrieveContactList();
});
}else{//update
var url = "/contacts/"+strId;
$.post(url, 
{ 'utf8':"✓", '_method':'put', 'authenticity_token': "lJxO7oZQ460Rw3+4bk/aO9kpKhdO3+bUFmt+cByPsC8=", 
'contact[name]': strName, 'contact[address]': strAddress,
'contact[phone]': strPhone, 'contact[email]': strEmail },
function(data){
retrieveContactList();
});
}
}

(replacing the request.parameters("bla") with the correct key values on the ceylon side of course)


it seems to not like the form encoding with xmlhttp request. When I debug into RequestImpl the formData is blank.  Can anyone else confirm?

Thanks,

Andy

Matej Lazar

unread,
Apr 18, 2013, 8:29:24 PM4/18/13
to ceylon...@googlegroups.com

True, there is a bug detecting content-type, if there is also encoding present.

it should work if you set content type to:
application/x-www-form-urlencoded;

instead of default one:
application/x-www-form-urlencoded; charset=utf-8


Fixed in master.

Matej.
--
You received this message because you are subscribed to the Google Groups "ceylon-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceylon-users...@googlegroups.com.
To post to this group, send email to ceylon...@googlegroups.com.
Visit this group at http://groups.google.com/group/ceylon-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Andrew Oliver

unread,
Apr 18, 2013, 9:01:02 PM4/18/13
to ceylon...@googlegroups.com
I fixed it before I read this....  

line 160 in RequestImpl.ceylon
                if (contentType.startsWith(applicationXWwwFormUrlEncoded) || contentType.startsWith(multiparFormData)) {

I also figured out how to build the sdk (or the parts I need to) on (Ubuntu) Linux via the ide (recorded for the record aka google):

change build.properties
"
sdk.version=0.5

module.ceylon.language.version=0.5
module.com.redhat.ceylon.compiler.version=0.5

dist.repo.dir=/usr/share/ceylon/repo
dist.libs.dir=/usr/share/ceylon/lib
  
ceylon.ant.lib=${dist.libs.dir}/ceylon-ant.jar
ceylon.executable=/usr/share/ceylon/0.5/bin/ceylon
"

right click on build.xml in the sdk project 
run as...
add this crap to the classpath (click external jars, everything in /usr/share/ceylon/{version}/lib)

then  rm -rf ~/.ceylon/repo/ceylon/net/0.5.2

run build targets clean,compile.publish 


It is possible not all of the above steps are necessary but it works for me.

Andrew Oliver

unread,
Apr 19, 2013, 5:05:47 PM4/19/13
to ceylon...@googlegroups.com
Any chance of getting this into a module release by Thursday?  It might eliminate a small amount of confusion when I publish the article with the example ;-)


On Thursday, April 18, 2013 8:29:24 PM UTC-4, Matej Lazar wrote:

Matej Lazar

unread,
Apr 24, 2013, 6:37:57 PM4/24/13
to ceylon...@googlegroups.com

Hi Andrew,

I've just released module ceylon.net/0.5.3


Matej.

Andrew Oliver

unread,
Apr 26, 2013, 9:19:47 AM4/26/13
to ceylon...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages