取得&使用ajax和Jquery更新数据

时间:2014-09-18 14:32:19

标签: javascript php jquery ajax twitter-bootstrap

我一直在研究基于论坛的系统。在jquery,php,bootstrap等的帮助下,我可以开发一个用户可以发布,删除和编辑的论坛。我已经为发送帖子的人定义了一个编辑按钮,点击鼠标,“模态”下来,并且会出现一些表格供用户输入他/她想要的信息。我一直在互联网上搜索正确的ajax方法,首先从服务器收集数据,并保存用户对其所做的更改,但我没有成功定义我正在寻找的东西。下面是模态代码,

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">Modal title</h4>
            </div>
            <div class="modal-body">
                <div class="container">
                    <form style="width: 550px;" action="" method="post" role="form">
                        <div class="from-group">
                            <label for="title">Title: </label>
                            <input class="form-control" type="text" name="title" id="title" value="" placeholder="Page Title">
                        </div>
                        <br>
                        <div class="from-group">
                            <label for="label">Label: </label>
                            <input class="form-control" type="text" name="label" id="label" value="" placeholder="Page Label">
                        </div>
                        <br>
                        <div class="from-group">
                            <label for="header">Header: </label>
                            <input class="form-control" type="text" name="header" id="header" value="" placeholder="Page Header">
                        </div>
                        <br>
                        <div class="from-group">
                            <label for="body">Body: </label>
                            <textarea class="form-control editor" name="body" id="body" row="8" placeholder="Page Body"></textarea>
                        </div>
                        <br>
                        <!-- <button style=" color:#FFFFFF; background-color: #4D6064"  type="submit" class="btn ">Submit</button> -->
                        <input type="hidden" name="submitted" value="1">
                        <br>
                        <br>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:0)

'正确'的ajax方法?

Ajax只是一种与服务器通信的方式。

您想收集哪些数据?

GET请求将请求服务器在响应中向您发回一些“数据”,这可能是任何“ajax”包装器库中的第一个示例,例如,此片段

$.ajax({
  url: "http://fiddle.jshell.net/favicon.png",
  beforeSend: function( xhr ) {
    xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
  }
})
  .done(function( data ) {
    if ( console && console.log ) {
      console.log( "Sample of data:", data.slice( 0, 100 ) );
    }
 });

来自jQuery.ajax http://api.jquery.com/jquery.ajax/

它向指定的url发送请求(忽略beforeSend函数,无论如何都没有做任何事情),然后在'.done'处理程序中处理响应。如果您不熟悉promises,只需将'.done'处理程序视为包含数据的回调,即在将来的某个时刻服务器将响应(希望)某些数据并且该函数处理它。

相关问题