2014-08-29 105 views
0

我在Parse.com上玩了一下,我正嘗試將HTML表單的內容發送到Parse.com 我是一種Javascript noob,所以出於某種原因,我找不到方法將我從表單輸入中獲得的變量傳遞給Parse.com進行處理。 這裏是我的代碼:將表單的輸入傳遞給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> 
+0

對於初學者,從'alert(text_value)'附近刪除'{'和'}'...... – Darren 2014-08-29 20:59:40

回答

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> 
相關問題