I try to do a jQuery live search for many input fields.
With only 1 input field (without array) it's working all great,
but with many search fields with array there is just happening nothing.
(The livesearch.php file is for now only saying "echo 'test';")
I hope you can help me.
Thanks for answer.
But it still doesn't work.
I just don't understand why the ajax-part doesn't work.
I edited my code to the following:
<html><head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<div id="main">
First search field:<br>
<input type="text" name="search[]" class="search" autocomplete="off">
<div></div>
Second search field:<br>
<input type="text" name="search[]" class="search" autocomplete="off">
<div></div>
</div>
<script>
$(document).ready(function() {
$('.search').on("keyup", function(e) {
var search_string = $(this).val();
// Do Search
if (search_string == '') {
$(this).next().fadeOut();
}else{
$(this).next().fadeIn();
//$(this).next().html("hallo"); //THIS WORKS!!!
$.ajax({
type: "POST",
url: "./livesearch.php",
data: { query: search_string },
cache: false,
success: function(data){
$(this).next().html(data); //THIS DOESN'T WORK!!!
}
});
};
});
});
</script>
</body>
</html>