2012-03-27 51 views
0

所以我看到這篇文章幫助解答了我的問題的一部分,但現在我的表單仍然不使用jQuery來發布表單。使用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發佈?

仍試圖找出如何處理這個問題?

+1

後呈現的HTML,這裏是jQuery代碼 – Rafay 2012-03-27 16:38:19

+0

哎呀對不起忘了,包括它。 – 2012-03-27 16:53:36

+0

信息已更新 – 2012-03-27 16:55:35

回答

0

嗯......這可能是一個愚蠢的問題,但你的意思是離開開放/關閉腳本標籤?如果不是,那可能是你的問題。

+0

這js是在外部js文件。 – 2012-03-27 19:03:34

0

您可以通過更改您的網址類似嘗試:

url : <?=site_url('Controller/Function');?> 

我希望工程