2013-06-28 80 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();