dongxi1680 2015-02-18 19:10
浏览 8
已采纳

jQuery提交功能不发送输入提交

I was looking for answer for my question but I didn't found solution. Here is similar topic link but I have different code and I don't know how to fit answer from this topic to my code.

Here is my problem. I'm sending my form with id order_form to test.php. Every form value is sending proper except input submit. My script is based on checking that <input id="sendform" type="submit" value="ORDER PRODUCT" name="sendform"/> is send.

Below is code that I use to send form.

$("#order_form").submit(function() {

    $.ajax({
           type: "POST",
           url: "includes/test.php",
           data: $("#order_form").serialize(), // serializes the form's elements.
           success: function(data)
           {
                alert(data);
           }
    });

    return false; // avoid to execute the actual submit of the form.
});

And here is content of test.php

echo '<pre>';
print_r($_POST);
echo '</pre>';

Here is examle form because my form is extremaly big.

  <form id="order_form">
      <input type="text" name="w2b" value="abc"/>
      <input id="sendform" type="submit" value="ZAMAWIAM" name="sendform"/>
  </form>
  • 写回答

2条回答 默认 最新

  • dongyikong6207 2015-02-18 19:19
    关注

    In HTML5 forms when you are passing through parameters and variables to the ajax functions the value data from "Submit Inputs" isn't passed through. So if you have a form set up as :

    <form>
    <input type="text" name="foo" value="bar">
    <input type="submit" name="submitTest" value="Hello World!">
    </form>
    

    The value of "submitTest" isn't being sent through. The only thing that gets sent through is the parameter "foo" with the value of "bar". "submitTest" only submits the form and executes your ajax call in this case.

    To fix this just add a hidden element in the form. Now it would look this

    <form>
    <input type="text" name="foo" value="bar">
    <input type="hidden" name="sendform" value="ZAMAWIAM">
    <input type="submit" name="submitTest" value="Hello World!">
    </form>
    

    This will send through the value to your ajax call and you can use it for whatever you might need it for.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址