【发布时间】:2012-08-20 16:47:44
【问题描述】:
所以我看到这篇文章帮助回答了我的部分问题,但是现在我的表单仍然没有使用 jquery 来发布表单。
How to remove the action attribute in the form_open_multipart() in Codeigniter?
这是在页面打开时呈现的 html 和生成它的 php 标记。
<?php $attributes = array('class' => 'validate', 'id' => 'pmForm'); ?>
<?php echo form_open('', $attributes ); ?>
<form id="pmForm" class="validate" accept-charset="utf-8" method="post" novalidate="novalidate">
* Validate the form when it is submitted
*/
var validateform = $("#pmForm").validate({
invalidHandler: function(form, validator) {
var errors = validator.numberOfInvalids();
if (errors) {
var message = errors == 1
? 'You missed 1 field. It has been highlighted.'
: 'You missed ' + errors + ' fields. They have been highlighted.';
$('.box .content').removeAlertBoxes();
$('.box .content').alertBox(message, {type: 'warning', icon: true, noMargin: false});
$('.box .content .alert').css({
width: '100%',
margin: '0',
borderLeft: 'none',
borderRight: 'none',
borderRadius: 0
});
} else {
$('.box .content').removeAlertBoxes();
}
},
showErrors : function(errorMap, errorList) {
this.defaultShowErrors();
var self = this;
$.each(errorList, function() {
var $input = $(this.element);
var $label = $input.parent().find('label.error').hide();
$label.addClass('red');
$label.css('width', '');
$input.trigger('labeled');
$label.fadeIn();
});
},
submitHandler: function(form) {
var dataString = $('#pmForm').serialize();
$.ajax({
type: 'POST',
url: '/path/to/my/php/submitfunction',
data: dataString,
dataType: 'json',
success: function(data) {
if (data.error) {
$('.box .content').removeAlertBoxes();
$('.box .content').alertBox(data.message, {type: 'warning', icon: true, noMargin: false});
$('.box .content .alert').css({
width: '',
margin: '0',
borderLeft: 'none',
borderRight: 'none',
borderRadius: 0
});
}
else
{
$('.box .content').removeAlertBoxes();
$('.box .content').alertBox(data.message, {type: 'success', icon: true, noMargin: false});
$('.box .content .alert').css({
width: '',
margin: '0',
borderLeft: 'none',
borderRight: 'none',
borderRadius: 0
});
$(':input','#pmForm')
.not(':submit, :button, :hidden, :reset')
.val('');
}
}
});
}
});
关于它为什么不使用 jQuery 发布的任何想法?
还在想办法解决这个问题吗?
【问题讨论】:
-
贴出渲染的html,jquery代码在哪里
-
抱歉,忘记包含它了。
-
尝试使用 firebug 解决任何 js 错误getfirebug.com
-
我有萤火虫,但我没有得到任何
标签: php jquery codeigniter