Unable to show the entire Div code in Ajax success function call
I have a button called RequestQuestions and on click of this button, i should be able to display all the questions. I have delayed the response by 10 secs but still the table doesn't load with content. When I write a regular function without ajax, the table shows with content but I need to make a ajax call. The table earlier used to load on page load but now it should happen on button click.
Below is the code I have tried
$("[id='Questions']").on("click", function(e) {
$.ajax({
type: "GET",
url: "${pageContext.request.contextPath}" + "/security/Questions",
async: false,
cache: false,
contentType: "application/json",
timeout: "10000",
success: function(response) {
alert("json name==="+response.questions.challengeQuestions[0].questionName);
alert("json ==="+response.questions.challengeQuestions[0].question);
// $('#formQuestSection').show();
// $('#Questions').hide();
},
failure: function(response) {
return;
},
error: function(response) {
return;
}
});
});
<input type="button" id="Questions" style="float: left;" name="Request Questions" value="Request Questions">
</input>
<div id="formQuestSection" class="sec-question">
<%int index = 0;%>
<c:forEach items="${securityVO.questions.challengeQuestions}" var="quest">
<div class="squestion">
<c:out value="${quest.question}"></c:out>
</div>
<%String questPath = "answers.challengeAnswers[" + index + "].questionName";%>
<form:input class="panelValue, hidden-form-field" path="<%=questPath%>" value="${quest.questionName}" />
<c:forEach items="${quest.answers}" var="ans">
<%String indexName = "qOption" + index;%>
<%String idName = "formQOption" + index;%>
<%String ansPath = "answers.challengeAnswers[" + index + "].answerKey";%>
<div class="sanswer">
<form:radiobutton name="<%=indexName%>" id="<%=idName%>" path="<%=ansPath%>" value="${ans.answerKey}" label="${ans.answer}" />
</div><br/>
</c:forEach>
<%index = index + 1; %>
</c:forEach>
</div>
right now $('#Questions').hide()
works fine but $('#formQuestSection').show()
doesn't show up. I am thinking the page is loading without displaying the content. Also I can see the table only but no content. Any help on this?
I am now able to get the response when I alert, can anyone help me with appending the content in the table in the ajax call? I'm pretty new to this.
<div id="formQuestSection" class="sec-question">
<%int index = 0;%>
<c:forEach items="${securityVO.questions.challengeQuestions}" var="quest">
<div class="squestion">
<c:out value="${quest.question}"></c:out>
</div>
<%String questPath = "answers.challengeAnswers[" + index + "].questionName";%>
<form:input class="panelValue, hidden-form-field" path="<%=questPath%>" value="${quest.questionName}" />
<c:forEach items="${quest.answers}" var="ans">
<%String indexName = "qOption" + index;%>
<%String idName = "formQOption" + index;%>
<%String ansPath = "answers.challengeAnswers[" + index + "].answerKey";%>
<div class="sanswer">
<form:radiobutton name="<%=indexName%>" id="<%=idName%>" path="<%=ansPath%>" value="${ans.answerKey}" label="${ans.answer}" />
</div><br/>
</c:forEach>
<%index = index + 1; %>
</c:forEach>
</div>
I have to remove this part of the code and put it in ajax success call.