Jump to content

Unwanted query string in the url


chauhanRohit

Recommended Posts

Hi guys,

 

I am using this code to open and close a pop up window, but as soon as i click the close button this

 

http://localhost/popup.php?random=&button=

 

automatically adds in the url, Please tell me what is wrong with the script

<script type="text/javascript">

 $(document).ready(function(){
    $('a.popup-window').click(function(){
       
       var popupBox = $(this).attr('href');
       $(popupBox).fadeIn(400);
	   
	   var popMargTop = ($(popupBox).height() + 24)/2;
	   var popMargLeft = ($(popupBox).width() + 24)/2;
	   
	   $(popupBox).css({
		   'margin-top' : -popMargTop,
		   'margin-left' : -popMargLeft
	   });
	   
	   $('body').append('<div id="mask"></div>');
	   $('#mask').fadeIn(400);   
	   return false;
	});
    
	$('button.close,#mask').live('click', function(){
		   $('#mask,.popupInfo').fadeOut(400,function(){
			   $('#mask').remove();
			   });	
			   return false;
			});	  	
    
       
 
 });
 $(document).keyup(function(e){
	 if(e.keyCode ==27){
		 $('#mask,.popupInfo, #popup-box').fadeOut(400);
		 return false;
		 }
	 });

 </script>
</head>

<body>
<a href="#popup-box" class="popup-window">Click</a>
  <div id="popup-box" class="popupInfo">
    <form>
      <label>ANYTHING</label></br>
      <input type="text" name="random"/></br>
      <button type="submit" name="button" class ="close">close</button>
    </form>
   </div> 

</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/289302-unwanted-query-string-in-the-url/
Share on other sites

Sorry, but changing the method to POST makes absolutely no sense.

 

The reason why you see parameters in the URL is because pressing the button submits the form. If you change the method, you're still submitting the form. The only difference is that now the parameters are sent via the message body rather than the URL. But they're still there.

 

Even worse, now the browser will issue a warning whenever you try to reload the page, because it needs to know whether it should resend the data. So, no, this is not the answer.

 

If you don't want to submit data, well, why have a form in the first place? Delete it, and the problem will go away.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.