HTML / JS:单击处理程序中的空formdata

时间:2016-08-22 06:17:01

标签: javascript jquery html

我有以下HTML / JS,我尝试提取formdata:

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" 
                type="text/javascript"></script>
        <script>

 $(document).ready(function(){
    $("#myform input[type=submit]").click(function(event) {
        event.preventDefault();
        fd = new FormData($("#myform")[0]);
        console.log(fd);
        fds = JSON.stringify(fd);
        console.log(fds);
    });
 });
        </script>
    </head>

    <body>
        <form id="myform" method="POST" enc-type="multipart/form-data">
            <input name="test" type="hidden" value="5" />
            <input type="submit" name="send" value="X" />
        </form>
    </body>
</html>

执行页面会提供空的FormData。为什么?有没有JSON.stringify的替代方案?

4 个答案:

答案 0 :(得分:1)

使用Range("H2:H" & nr_rows) = Application.WorksheetFunction.SumIfs(dates, int001, int002, int003, unique_dates, int001, int002, int003, ">0")

.serializeArray()

答案 1 :(得分:0)

$(document).ready(function(){
    $("#myform input[type=submit]").click(function(event) {
        event.preventDefault();
        fd = $("#myform").serialize();
      
        alert(fd)
    });
});
    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<form id="myform" method="POST" enc-type="multipart/form-data">
            
  <input name="test" type="hidden" value="5" />
           
  <input type="submit" name="send" value="X" />
 </form>

答案 2 :(得分:0)

在序列化之前,你应该从FormData读取字段:

 $(document).ready(function(){
    $("#myform input[type=submit]").click(function(event) {
        event.preventDefault();
        fd = new FormData($("#myform")[0]);
        console.log(fd);
        fds = JSON.stringify(fd.getAll());
        console.log(fds);
    });
 });

答案 3 :(得分:0)

您可以使用serialize(),如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="hello.aws.graph.BatteryGraph$PlaceholderFragment" >
<LinearLayout
android:id="@+id/l1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin1top"
android:orientation="vertical">
<lecho.lib.hellocharts.view.LineChartView
    android:id="@+id/chart"

    android:layout_width="match_parent"
    android:layout_height="match_parent" >

</lecho.lib.hellocharts.view.LineChartView>
</LinearLayout>
</RelativeLayout>

看看这个:https://api.jquery.com/serialize/