Hi, I have a problem passing parameters via post.
I’ve examined the log file of a scaffolded version against my AJAX
version and can’t figure out what’s wrong. I think I’ve also isolated
the problem to be parameter passing by using logger.debug.
the AJAX part;
var name=document.getElementById(“name”).value;
var notes=document.getElementById(“notes”).value;
var parent_nid=document.getElementById(“parent_nid”).value;
var
post_params=“name=”+name+"¬es="+notes+"&parent_nid="+parent_nid+"&authenticity_token="+window._token;
var req=XMLHttpRequest();
req.open(“POST”,"/categories/create",true);
req.setRequestHeader(“Content-type”,“application/x-www-form-urlencoded”);
req.send(post_params);
The controller part: (mostly from scaffold)
@category=Category.new(params[:category])
logger.debug “name:”
logger.debug @category.name
logger.debug “notes:”
logger.debug @category.notes
logger.debug “parent_nid:”
logger.debug @category.parent_nid
Category.create(@category)
redirect_to :controller=>‘dashboard’
the log part:
Parameters: {“name”=>“abc”,
“authenticity_token”=>“d8c79e2216df723f373a9170fa364f9a3c147092”,
“notes”=>“abcde”, “parent_nid”=>“0”}
name:
notes:
parent_nid:
–
Anyone has any idea what’s wrong?