ajaxform() & sortable('serialize') 和 codeigniter .. 提交表单字段和列表元素
我有一个表单和一个 sortable() 列表,用户可以从预先填充的列表中拖动到空的 UL 中。用户可以将他们想要的 LI 拖到这个空的 UL 中。还有一个带有一些文本框的表单,用户可以填写并单击提交。
我可以让 ajaxform 提交表单数据并将其显示在 flashdata 会话中,但我无法让它显示 allowed_fields 数据。 (这是可排序的列表)。我知道它对其进行序列化,因为运行 alert(serializedList);
返回元素的序列化列表。
这是生成可排序列表的 JS:
/**
* sortable ul items
*
* this is used for the add levels page to associate allowed_fields
* to a level.
*/
$('.block-list').sortable({
connectWith: '.block-list',
placeholder: 'placeholder'
});
这是处理 ajaxSubmit 的 JS:
/**
* showResponse(data)
* show the response if the form submission is successful
* @param {object} data object of message or success
* @return {null}
*/
function showResponse(data){
alert(serializedList);
if (data.errorStatus == 1){
$.jGrowl(data.message, { theme: 'error' });
}else{
$.jGrowl(data.message, { theme: 'success' });
}
}//end showResponse()
/** @type {Object} setup the options for the ajax submit forms. */
var submitOptions = {
success: showResponse,
beforeSubmit: function(){ serializedList = $("#allowed-fields-list").sortable('serialize'); },
dataType: 'json',
resetForm: true ,
data: { allowed_fields: serializedList }
};
$("#addlevel-form").ajaxForm(submitOptions);
这是处理表单数据的代码点火器函数。 .
public function addlevelprocess(){
$message = array(
'message' => 'Successfully Added The Level To The Database! WHOA!:'.$this->input->post(),
'errorStatus' => 0
);
$this->session->set_flashdata('post', $this->input->post());
echo json_encode($message);
}
我怎样才能让ajaxform发送表单字段数据和sortables()数据。
i have a form and a sortable() list where a user can drag from a pre populated list, into an empty UL. The user would drag the LIs that they want into to this empty UL.. There is also a form with a few text boxes that the user fills out and clicks submit.
I can get the ajaxform to submit the form data and display it in a flashdata session, but i cant get it to show the allowed_fields data. (which is the sortable list). I know its serializing it because running alert(serializedList);
returns the serialized list of elements.
This is the JS to generate the sortable lists:
/**
* sortable ul items
*
* this is used for the add levels page to associate allowed_fields
* to a level.
*/
$('.block-list').sortable({
connectWith: '.block-list',
placeholder: 'placeholder'
});
This is the JS to process the ajaxSubmit:
/**
* showResponse(data)
* show the response if the form submission is successful
* @param {object} data object of message or success
* @return {null}
*/
function showResponse(data){
alert(serializedList);
if (data.errorStatus == 1){
$.jGrowl(data.message, { theme: 'error' });
}else{
$.jGrowl(data.message, { theme: 'success' });
}
}//end showResponse()
/** @type {Object} setup the options for the ajax submit forms. */
var submitOptions = {
success: showResponse,
beforeSubmit: function(){ serializedList = $("#allowed-fields-list").sortable('serialize'); },
dataType: 'json',
resetForm: true ,
data: { allowed_fields: serializedList }
};
$("#addlevel-form").ajaxForm(submitOptions);
and this is the code igniter function that will handle the form data..
public function addlevelprocess(){
$message = array(
'message' => 'Successfully Added The Level To The Database! WHOA!:'.$this->input->post(),
'errorStatus' => 0
);
$this->session->set_flashdata('post', $this->input->post());
echo json_encode($message);
}
how can i get ajaxform to send both form field data and the sortables() data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终使用 ajaxSubmit() 并通过数据传递序列化表单信息:
i ended up using ajaxSubmit() and passing the serialized form information via data: