开发者

Jquery ajax not refreshing in modal

开发者 https://www.devze.com 2023-03-23 08:36 出处:网络
I\'m using a fancybox modal to display comments from a news page pulled from a mysql database. The modal also has a section that allows users to post new comments. I\'m using jquery to send the form i

I'm using a fancybox modal to display comments from a news page pulled from a mysql database. The modal also has a section that allows users to post new comments. I'm using jquery to send the form information to another script for processing.

Instead of returning the successful message, it's posting the informat开发者_运维问答ion and redirecting to the page instead of displaying the information in the modal.

Here's the jquery that should cause this to happen:

$(document).ready(function(){ 
$("#submit").click(function() {
/* Set some vars */
                        var messageText = $("textarea#message").val();
                        var newsID = $("hidden#newsid").val();


                        $.post('/process/newmsg.php',
                            { message : messageText, newsid: newsID },
                            function(data) {
                                $("#fancybox_content").before(data);
                            }
                        );



});

});

Any idea what I'm missing here?


this is not a valid selector: $("hidden#newsid"). So, "newsID" is empty and the post parameters give syntax error

{ message : messageText, newsid: },


Try $("#fancybox_content").html(data);

before() wont put the result INSIDE the fancybox_content, it will put it before it.

also, if the result is a full html document including the head and everything, it will cause problems. you should parse the results first


Assuming #submit is a submit button, you need to cancel the default behavior of that button, which is to submit the form. Either return false from your click handler function or use e.preventDefault().

0

精彩评论

暂无评论...
验证码 换一张
取 消