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.
See this post on how to fix your Java Servlet to decode HTML input:
Java: How to unescape HTML character entities in Java?
PS. Change  
to
in your code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.