duanji9481 2015-03-10 14:48
浏览 15

将数据发布到php页面

        <html>
<head>


    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript">
        $(function()
        {
            $('button[type="submit"]').on('click',function(e)
            {
                e.preventDefault();
                var submit_value = $(this).val();
                jQuery.post
                (


                );
            });
        });
    </script>
</head>
<body>
    <form method="post" action="php page" id="the-form">
       Name <input type="text" name="name" > <br/>
           Number <input type="text" name="number" > <br/>
        <button type="submit" name="Submit">submit</button>
          </form>

</body>
</html>

What should I write to jQuery.post to send the data from the form to a php page, I tried some posibilities but when I clicked submit the php page responded "No value". I don't have to change anything at the php page just in this script.

  • 写回答

1条回答 默认 最新

  • dongxiji0687 2015-03-10 14:58
    关注

    Your references are off

    $('button[type="submit"]').on('click',function(e)
    

    This will observe your submit button, not the form. So when you get to this

    $(this).val();
    

    It's looking at your submit button (which has no value), not your form data. Instead, you should grab the form and observe the submit event and then serialize the data

    $("#the-form").on( "submit", function(e) {
        e.preventDefault();
        var data = $(this).serialize();
        jQuery.post('your/url.php', data, function(resp) {
            //Do something with the response here
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?