Vicky
Vicky

Reputation: 982

.load() function load the entire page on click

I have use modal for user sign up and its working correctly when user click on register link the modal popup load perfectly now i am making comment box where user can comment on pictures and if user is not login i want to load the same popup modal which is bind with register link some how i am successful but the error is that the load() function load the entire page for me on the same page i am totally confuse. here is my coding .

$("#button").click(function(){
                          var user=$("#username").val();
                          var message=$("#form-s-t").val();
                    if(user != ""){
                      if(message != ""){
                            $.ajax({
                                type:"post",
                                url:"retriveing.php",
                                data:"name="+name+"&message="+message+"&action=addcomment",
                                success:function(data){
                                showComment();
                                }
                            });
                           $("#form-s-t").val('');
                      }
                        else {alert("you can not post empty comments");}
                    }

Here in else portion i am loading the popup.

else{
                            $('.topopup').load("#toPopup");
                            }
                        });
                   });

The popup which loads with register link is this. correct popup

User which is not login want to comment it load the page twicly and oppositly as shown in picture.

wrong popup

Upvotes: 2

Views: 214

Answers (3)

Aitazaz Khan
Aitazaz Khan

Reputation: 1605

There is no need of load() function if the model resides in the same page . try to trigger the register link which can be done like that. Remove the load function in your else portion and just write the code I have give below.

 $('.topopup').trigger("click");

.topopup 

is a id of register link and you want to load this popup when user is not sign in and want to comment. I hope it will work for you. if the model resides in the same page.

Upvotes: 1

Skadi2k3
Skadi2k3

Reputation: 66

You are loading an anchor, so the same page is getting injected into the elements with class .topopup. Just check your register button's onclick function and use else { thatFunction(); } if you want to recreate the same behaviour. [Also try using retrieving.php as a filename.]

To clarify: load("#toPopup") is equiv. to load(currentURL+"#toPopup"). First parameter is an URL string, not a selector string.

Upvotes: 0

Neo Ko
Neo Ko

Reputation: 1405

From you screenshot, you send the wrong argument to the server.

$('.topopup').load("#toPopup");
// you just load "/#toPopup" page from the server
// and the server return a new page to you
// then jQuery update '.topopup' with the new
// page

Upvotes: 0

Related Questions