2012-02-02 93 views
0

我正在嘗試構建移動應用程序,但在獲取Jquery/Javascript的基礎知識時遇到了一些麻煩。 我想讓它可以輸入任何我想要進入輸入字段的值,然後發佈它,它會在上面發佈,並允許我在輸入字段中輸入更多內容,並且它會在最後一篇文章之後發佈。發佈表單數據Jquery

這是我的代碼到目前爲止。不知道下一步該去哪,或者如果我正朝着正確的方向前進。

<!DOCTYPE HTML> 
    <HTML> 
    <script src="http://code.jquery.com/jquery-latest.js"></script> 

    <script> 

     $('#commentForm').submit(function(){ //listen for submit event 
     $.each(params, function(i,param){ 
      $('<input />').attr('type', 'show') 
       .attr('value', param.value) 
       .appendTo('#commentForm'); 
     }); 



     return true; 
    }); 



    </script> 
    <BODY> 
    <form id="commentForm" method="POST"> 
     <textarea cols="30" rows="6" name="comment" title="Enter a comment"> 
     </textarea> 
     <input type="submit" value="Post"/> 
     <input type="reset" value="Reset"/> 
    </form> 
    <div id="box"> 

    </div> 

    </BODY> 

    </HTML> 

回答

1

給提交按鈕稱爲ID「提交」

function onSuccess(data, status) { 
     data = $.trim(data); 
      //make a div with id "notification" before running this code 
     $("#notification").html(data); 
     $.mobile.hidePageLoadingMsg(); //used on jquery mobile to hide a loader 
    } 

    function onError(data, status) { 
     data = $.trim(data); 
     $("#notification").html(data); 
     $.mobile.hidePageLoadingMsg(); //used on jquery mobile to hide a loader 
    } 
    $("#submit").click(function() { 
     $.mobile.showPageLoadingMsg(); //used on jquery mobile to show a loader 
     var formData = $("#commentForm").serialize(); //get all data from form 
      //do the POST thingies 
     $.ajax({ 
      type: "POST", 
      url: "url_to_your_php_interpreter", 
      cache: false, 
      data: formData, 
      success: onSuccess, 
      error: onError 
     }); 

     return false; 
    }); 

我使用這個腳本登錄用戶的。 PS:你會「回聲」從PHP解釋器的一切將顯示在身份證「通知」至少你會(可能)創建