Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Post Callback filter select data

Ich have the following site with JQuery:

<html>
<head>
<title>Testpost</title>
<script type="text/javascript" src="../jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	var sendtest = $("#sendtest");
	sendtest.keyup(function(){
	     $.post( 
        "test.php",
         { nur: sendtest.val() },
         function(data) {
         $('#receivetest').html(data);
			}
		 );
	});
	});	
</script>
</head>
<body>
	<input type="text" name="season" id="sendtest"/>
	<div id="receivetest"></div>
</body>
</html>

And following test.php:

<?php


   $nur = $_POST['nur'];
   echo $nur;


?>
<p id="hello">Hello World!</p>

Now I want to see on the receivetest-div only echo $nur; ! What must I do for that?

like image 634
Jürgen Hohlkopf Avatar asked Jan 24 '26 18:01

Jürgen Hohlkopf


1 Answers

It is not a good practice to code like this. It would be better to add a parameter in your PHP file which will hide the div when you don't need it.

However, you can hide the div like that:

$('#receivetest').find('#hello').hide();

This will keep the html of the <div id="hello"> and its content, and hide it to the client.

You can also remove the div by doing this:

$('#receivetest').find('#hello').remove();
like image 73
4br3mm0rd Avatar answered Jan 26 '26 08:01

4br3mm0rd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!