2012-02-02 88 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解释器的一切将显示在身份证“通知”至少你会(可能)创建