Hi Marian,
I have the work done for an AJAX setup but I am having some trouble getting the module page to respond. It looks like some of the data I am POSTing to the module page is not getting through and I am not sure why.
I have set up a new page that parses the search results and returns them as a JSON object (pageref:"search_results_json"). I am POSTing to the module and using that JSON page as the resultsURL parameter:
var request = $.ajax({
method: "POST",
url: "<%=request.getContextPath() %>/do.search",
data: {
query: "california",
pageSize: "100",
resultsURL: "$CMS_REF(pageref:"search_results_json")$"
}
});
The call works - the module redirects to the JSON page, which means that the resultsURL parameter is working, but it is not getting the "query" parameter I am also passing, so no actual search is taking place.
I'm not sure what the difference is between this jQuery call and what I was using originally as a form. This is what the old form looked like:
<form method="post" action="<%=request.getContextPath() %>/do.search" name="fss">
<input type="text" name="query" class="search-input" />
<input type="hidden" name="resultsURL" value="$CMS_REF(pageref:"search_results")$" />
<input type="hidden" name="pageSize" value="10" />
<input type="submit" value="Search" />
</form>
The parameters seem to line up to me. Any ideas why the query is not getting through?
For reference, here is the code for the JSON page that I am having the search module redirect to:
<%@ page language="java" contentType="application/json; charset=UTF-8" %>
<%@ taglib uri="fs-search" prefix="fss" %>
<%@ page import="java.util.*" %>
$CMS_TRIM(level:4)$
{
<fss:getSearchDetails>
<fss:isTrue>
"query":"<%=query %>",
"results":[
<fss:iterateResults>
{
"title":"<%=title %>",
"url":"<%=url %>",
"content":"<%=content.substring(0, Math.min(content.length(), 300)) %>"
},
</fss:iterateResults>
]
</fss:isTrue>
<fss:isFalse>
"query":"<%=query %>",
"results":[]
</fss:isFalse>
</fss:getSearchDetails>
}
$CMS_END_TRIM$