Exploring web development using play framework and ajax. I'm looking to pass a string from a form to a controller using ajax, but unsure of how to go about it. Can anyone assist me with this? Here's my code snippet: html:
<form onsubmit="return newSearch();" id="formId">
<input type="search" placeholder="Search for more" id="searchBar_chat">
</form>
<script type="text/javascript" >
function newSearch()
{
var s = document.getElementById("chatDialgue");
var searchValue = document.getElementById("searchBar_chat").value;
s.innerHTML = s.innerHTML + '<li>'+ searchValue +'</li>';
document.getElementById("searchBar_chat").value ="";
$.ajax({
url: "DataMatch/searchContentMatch",
type:"GET",
cache: false,
dataType:"text",
data:"searchValue",
success: function (responseData) {
s.innerHTML = s.innerHTML + '<li>'+responseData+'</li>';
}
});
return false;
}
</script>
controller:
public class DataMatch extends Controller{
public String searchContentMatch (String search) {
// Search match
return "HI"+search;
}
}