简体   繁体   English

特定的div使用ajax或jquery刷新onsumbit

[英]Particular div to refresh onsumbit using ajax or jquery

I want a particular div on a page that contains database field to refresh itself to bring out the currenty entry onsubmit of a form. 我希望包含数据库字段的页面上的特定div刷新自身以在提交表单时显示当前条目。 the div that contains the record is called #new_entry 包含记录的div称为#new_entry

 <div id="new_entry"></div>
    <script>
    $(document).ready(function(){
        $("#form3").on('submit',function(event){
            event.preventDefault();

            data = $(this).serialize();
            $.ajax({
            type: "POST",
            url: "../calls/insert_call_love.asp",
            data: data
            }).success(function() {

     $("#feedback").append("<div class='messages' style='border:1px purple solid; padding:2px; margin:5px;'>Your have loved this photo </div>");

                setTimeout(function() { 
                    $(".messages").fadeOut(function(){
                        $(".messages").remove();
                    }); 
                }, 1000);

                $("input[type=text]").val("");

            });
        });
    });
    </script>

this is what i'm posting to the insert_call_love.asp 这就是我要发布到insert_call_love.asp的内容

<form action="<%=MM_editAction%>" method="post" name="form3" id="form2">
          <input name="comment" type="text" id="comment" size="50" />
          <input name="imageField3" type="image" id="imageField3" src="../imgs/buttons/comment.png" align="bottom" />
          <input name="wardrobe" type="hidden" id="wardrobe" value="1" />
          <input name="comme" type="hidden" id="comme" value="2" />
          <input name="comfn" type="hidden" id="comfn" value="3" />
          <input name="photo_id" type="hidden" id="photo_id" value="4" />
          <input name="ctype" type="hidden" id="ctype" value="picture" />
          <input name="resp_email" type="hidden" id="resp_email" value="5" />
          <input name="MM_insert" type="hidden" id="MM_insert" value="form2" />
        </form>

In your code, you have to add a variable to success(function()) function 在您的代码中,必须将一个变量添加到success(function())函数

success(function(msg)

** "msg" **will contain data which you want to return from below url:- ** "msg" **将包含您要从以下网址返回的数据:-

url: "../calls/insert_call_love.asp",

then you can assign this data to any div 那么您可以将此数据分配给任何div

}).success(function(msg) {
   $('#new_entry').html(msg);
}

Note: variable "msg" will contain all the data which you have printed on the page "insert_call_love.asp" 注意:变量"msg"将包含您在页面"insert_call_love.asp"上打印的所有数据。

Well depending on what you are doing on the server side with this post...You would need to query the DB and retrieve the latest item, and send it back/echo it out as JSON. 好吧,这取决于您在服务器端正在执行的操作...您将需要查询数据库并检索最新的项目,然后将其发送回/以JSON回显。

So in pseudocode steps... 所以在伪代码步骤中...

     Process posted variables...
       Query DB for latest entry..
           Echo out as JSON...

Then do something like ... 然后做类似...

.success(function(data) {
    $('#new_entry').html(data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM