将表单的输入传递给Parse.com

时间:2014-08-29 20:49:24

标签: javascript jquery parse-platform

我正在和Parse.com玩一下,我正在尝试将HTML表单的内容发送到Parse.com 我是一个Javascript noob所以由于某种原因我找不到一种方法来传递我从表单的输入到Parse.com进行处理的变量。 这是我的代码:

<div class="main">
<form action="">
<label>Insert your ingridient :</label>
<input type="text" id="text" name="name" value="" />
<input type="button" id="text_value" value="Get Value"/>

  <script type="text/javascript">
$(document).ready(function() {
$('#text_value').click(function() {
    var text_value = $("#text").val();{
    alert(text_value);
        }
    });
});

Parse.initialize("myAPIKey", "myAPIKey");
    var GameScore = Parse.Object.extend("GameScore");
    var gameScore = new GameScore();


    gameScore.save({
        name: text_value,
            }, {
        success: function(gameScore) {
        // The object was saved successfully.
        },
        error: function(gameScore, error) {
        // The save failed.
        // error is a Parse.Error with an error code and description.
  }
});
  </script>

1 个答案:

答案 0 :(得分:0)

您应该将执行保存的代码包装在函数中,然后在用户单击按钮时调用它。您的{}括号也有一些错误。在编写代码时缩进代码将帮助您避免这种情况。

<div class="main">
<form action="">
<label>Insert your ingridient :</label>
<input type="text" id="text" name="name" value="" />
<input type="button" id="text_value" value="Get Value"/>

<script type="text/javascript">
    $(document).ready(function() {
        $('#text_value').click(function() {
            var text_value = $("#text").val();
            save(text_value);
        });

        Parse.initialize("myAPIKey", "myAPIKey");
        var GameScore = Parse.Object.extend("GameScore");
        var gameScore = new GameScore();

        function save(value) {
            gameScore.save({name: text_value}, {
                success: function(gameScore) {
                    // The object was saved successfully.
                },
                error: function(gameScore, error) {
                    // The save failed.
                    // error is a Parse.Error with an error code and description.
                }
            });
        };
    };
</script>