单击“提交”按钮后,将数据发送到Parse

时间:2013-11-07 14:47:08

标签: javascript parse-platform

我想使用JavaScript / jQuery Mobile捕获用户输入的日期,然后按下提交按钮后将其发送到parse.com数据云。

使用下面的代码,我可以自动发送数据进行解析,但我不确定如何通过点击提交按钮来触发此事件。

如何将两者联系在一起?

<!-- Home -->
<div data-role="page" id="page1">
    <div data-role="content">
        <form id="dansform" action="dansform" method="POST" class="dansform">
            <div data-role="fieldcontain" class="date">
                <label for="date">
                    Date
                </label>
                <input name="date" id="date" placeholder="date" value="Select today's date"
                type="date" data-mini="true">
            </div>
            <input id="submit" type="submit" data-theme="c" value="Submit" data-mini="true"
            class="submit">
        </form>
    </div>
</div>


<script type="text/javascript">

Parse.initialize("X", "X");

  var TestObject = Parse.Object.extend("TestObject");
  var testObject = new TestObject();
  testObject.save({foo: "bar"}, {
    success: function(object) {
      alert("yay! it worked");
    }
  });

</script>

1 个答案:

答案 0 :(得分:1)

解决方案是onsubmit事件。

   <form onsubmit="dosomthing(); return false;" id="dansform" action="dansform" method="POST" class="dansform">
        <div data-role="fieldcontain" class="date">
            <label for="date">
                Date
            </label>
            <input name="date" id="date" placeholder="date" value="Select today's date"
            type="date" data-mini="true">
        </div>
        <input id="submit" type="submit" data-theme="c" value="Submit" data-mini="true"
        class="submit">
    </form>