I need to dynamically generate some bottoms based on the return of ajax get call
@.getJSON("SearchByName", {"name":searchstring}, function(data){
data = data.replace(/ /g, " ");
var pop = "<p>" + data + "</p><br/><button style=\"border-radius:
4px;\" onclick=getDatabyName(\"" + data +"\")>Load
Locations</button>";
.....
Since the return data may have space so I have to replace all spaces with
When users press the generated bottom to execute getDatabyName
, it calls a Servlet to query a database. However, the query within the Java Servlet returns nothing because the space characters are not properly encoded. I tried to do another replace inside getDatabyName
but still the same. I have ways to work around this but want to know the proper ways (either in Javascript or in Java) to handle this situation.