从Javascript表单调用类方法

Call a class method from Javascript form

本文关键字:类方法 调用 表单 Javascript      更新时间:2023-09-26

为了动态创建表单,我(在js函数内部)做了一些事情:

member = memberInfo.values[0];
// create the sign up form
var f = document.createElement("form");
f.setAttribute('method',"post");
f.setAttribute('name',"linkedInForm");
f.setAttribute('action', "users/register");
// add fields to the form
var fName = document.createElement("input");
fName.setAttribute('type',"hidden");
f.setAttribute('name',"linkedInForm");
fName.setAttribute('value',member.firstName);

我正在将字段添加到表单中

// append fields to the form
f.appendChild(fName);

然后提交:

document.getElementsByTagName('body')[0].appendChild(f);
f.submit();

这个js表单是由类"users"(f.setAttribute('action', "users/register");)中名为"register"的方法处理的

但我得到的只是一个错误500内部服务器错误。和在CodeIgniter日志中:

An Error Was Encountered. The action you have requested is not allowed.

有人有主意吗?

此错误似乎是由Security.php生成的,请在config文件夹的config.php中将csrf_protection更改为false

$config['csrf_protection'] = FALSE; 

你最好看看下面的链接,以获得更多的参考

http://ellislab.com/forums/viewthread/163976/