Hab das soweit hingekriegt.
<body>
<form id="form" action="./results.php">
<label for="q">Search</label>
<input type="text" id="q" name="q" />
<input type="submit">
</form>
<div class="container" id="container"></div>
<script>
jQuery('document').ready(function () {
jQuery('#form').submit(function(event){
event.preventDefault();
console.log("works");
$.ajax({
type: "GET",
contentType: "application/json",
url: "./results.php",
data: "{}",
dataType: "json",
success: function (data) {
for(var i=0; i<data.length; i++){
$("#container").append("<div><h2>"+data[i].title+"</h2><p>"+data[i].content+"</p></div>");
}
},
error: function (err) {
console.log(err);
}
});
});
});
</script>
</body>
jetzt habe ich allerdings das Problem, dass anscheinend ein leeres string über ajax geschickt wird, weil, ich bei jeder Suchanfrage alle artikel kriege. Ohne ajax bekomme ich nur die Artikel die ich möchte.
Gruß
Werkstudent1