2013-06-28 125 views
1

我有一個愚蠢的問題,我知道它真的很愚蠢,但我無法找到故障
我想提交一個基於ajax響應的貝寶形式。
問題是,阿賈克斯部分工作正常,但仍然沒有提交表格
首先,我想告訴我,我使用的是一個按鈕(而不是提交按鈕)的形式
上該按鈕的JavaScript函數被調用,如果Ajax響應爲正,那麼形式將得到提交用表單提交使用javascript問題

,這裏是我的腳本

<script> 
function mustvalid() { 

    var company_name = document.forms["cord_form"]["company_name"].value; 
    var slogan = document.forms["cord_form"]["slogan"].value; 
    var cord_email = document.forms["cord_form"]["cord_email"].value; 
    var company_do = document.forms["cord_form"]["company_do"].value; 
    var brand_color = document.forms["cord_form"]["brand_color"].value; 
    var imaginary = document.forms["cord_form"]["imaginary"].value; 
    var ex_logo = document.forms["cord_form"]["ex_logo"].value; 

    alert('hiidoooo'); 

    $.post("<?php echo base_url();?>ajax/set_custom_order", { 
     'company_name': company_name, 
      'slogan': slogan, 
      'cord_email': cord_email, 
      'company_do': company_do, 
      'brand_color': brand_color, 
      'imaginary': imaginary, 
      'ex_logo': ex_logo 
    }, 

    function (data) { 
     if (data == "done") { 
      alert(data); 
      document.getElementById('cord_form').submit(); 
      // this line isnt working so the alert following this line is also not working; 
      alert('hmm'); 
     } else { 
      alert('hii'); 
     } 
    }); 
}  
</script> 

<div class="pitch single"> 
     <h1>Custom Order</h1> 

    <!--<?php echo $cms[0]['content_desc']; ?>--> 
</div> 
<div id="top_adv"> 
    <?php echo $top_adv; ?> 
</div> 
<link href="<?php echo base_url(); ?>css/stylish-select.css" rel="stylesheet" type="text/css" media="all" /> 
<div class="content"> 
    <form name="cord_form" id="cord_form" method="post" action="abc.php"> 
     <div class="contact_us_form_space"> 
      <div> 
       <input type="text" value="Name of Company" name="company_name" class="contact_name contact_input" /> 
      </div> 
      <div> 
       <input type="text" value="Slogan [If Any]" name="slogan" class="contact_email contact_input" /> 
      </div> 
      <div> 
       <input type="text" value="Email" name="cord_email" class="contact_email contact_input" /> 
      </div> 
      <textarea class="contact_message" name="company_do" value="What does your company do?" onfocus="if(this.value == 'What does your company do?') { this.value = ''; }" onblur="if (this.value == '') { this.value='What does your company do?'; }">What does your company do?</textarea> 
      <textarea class="contact_message" name="competitors" value="What sets you apart from competitors?" onfocus="if(this.value == 'What sets you apart from competitors?') { this.value = ''; }" onblur="if (this.value == '') { this.value='What sets you apart from competitors?'; }">What sets you apart from competitors?</textarea> 
      <textarea class="contact_message" name="brand_color" value="What are your brand colors [If any]" onfocus="if(this.value == 'What are your brand colors [If any]') { this.value = ''; }" onblur="if (this.value == '') { this.value='What are your brand colors [If any]'; }">What are your brand colors [If any]</textarea> 
      <textarea class="contact_message" name="imaginary" value="Do you have any specific imagery in mind?" onfocus="if(this.value == 'Do you have any specific imagery in mind?') { this.value = ''; }" onblur="if (this.value == '') { this.value='Do you have any specific imagery in mind?'; }">Do you have any specific imagery in mind?</textarea> 
      <textarea class="contact_message" name="ex_logo" value="Examples of logos you like and why?" onfocus="if(this.value == 'Examples of logos you like and why?') { this.value = ''; }" onblur="if (this.value == '') { this.value='Examples of logos you like and why?'; }">Examples of logos you like and why?</textarea> 
     </div> 
     <img src="<?=site_url('home/securimage')?>" title="captcha" id="captcha2" /> 
     <input type="text" name="captcha_code" size="10" maxlength="6" /> <a href="#" onclick="document.getElementById('captcha2').src = '<?=site_url('home/securimage')?>?' + Math.random(); return false">[ Different Image ]</a> 

     <br/> 
     <?php echo @$_SESSION[ 'ctform'][ 'captcha_error'] ?> 
     <br/> 
     <input type="hidden" name="amount" value="$10"> 
     <input type="hidden" name="lc" value="US"> 
     <input type="button" value="Send" name="submit" class="contact_submit" onclick="mustvalid()" /> 
    </form> 

我只是不知道什麼錯誤會在這裏; 請幫助

+2

發生了什麼事?發生了什麼錯誤? $ .post()'回調中的'done'變量是否與「完成」不同? – sdespont

+0

How do you say ___ajax部分工作fine___?你有沒有試過'console.log(data)'?或者什麼'警報(數據)'打印?您需要將它放在回調開放大括號後面,在_if分支中__not__ –

回答

0

嘗試將按鈕的名稱更改爲「submit」以外的名稱。 It might be causing a conflict。而且,由於你使用jQuery,爲什麼不改變你的行:

$("#cord_form").submit(); 
0

你正在做正確的,但有些時候名稱衝突,從而改變ID的名稱,然後再試一次 希望它會工作:

$("#myform").submit(); 
document.getElementById('myform').submit(); 
document.myForm.submit();