weixin_33728708 2019-09-04 18:04 采纳率: 0%
浏览 13

在ajax调用中显示表

Table

I have a table that I used to display on page load but now I need to display on click of a button 'Request Questions'.

[<tr id="displayQuestions">
        <td>
            <div style="width: 100%; ">
            <fieldset class="panelBorder">
                <legend class="panelTitle">Identity Information</legend>
                <form:label class="panelLabel" path="" style="width: 30%;">Credit History Questions</form:label>
                <form:input id="formChallengeResponse" class="panelValueDisabled" path="challengeResponse" style="width: 70%;" readonly="true"/>
                <form:label class="panelLabel" path="" style="width: 30%;">One-time Passcode</form:label>
                <br><br><br>
                <input type="button" id="creditQuestions" style="float: left;" name="creditQuestions" value="Request Credit History Questions"></input>
                <br>
                <form:input id="formOTPResponse" class="panelValueDisabled" path="otp" readonly="true"/>
                <div id="formTuAuthFailed" class="sectionErrorFull" style="color: #666666; text-align: center; font-weight: bold;">Insufficient data available for credit history questions. <br> Please validate borrower's identity using an alternative method.<br><br><br><br></div>
                <div id="challengeQuestionsReponseFailed" class="sectionErrorFull" style="color: #666666; text-align: center; font-weight: bold;">Please validate borrower's identity using an alternative method.<br><br><br><br><br></div>
                <div id="formSecurityQuestSection" class="security-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>
                <form:input id="formNoQuestion" class="panelValue, hidden-form-field" path="isNoQuestion" />
                <form:input id="challengeQuestionFailure" class="panelValue, hidden-form-field" path="responseFailure" />
            </fieldset>
            </div>
        </td>
    </tr>][1]

$("[id='creditQuestions']").on("click", function(e)
    {
    alert("testing security==");
    $.ajax({
            type: "GET",
            url: "${pageContext.request.contextPath}" + "/security/creditQuestions",

            contentType: "application/json",
            success: function (response) {
                alert("testing security after succes==");
                alert("json name==="+response.questions.challengeQuestions[0].questionName);
                alert("json ==="+response.questions.challengeQuestions[0].question);


                 $.each(response, function(value, key) {                 
                     alert("response"+ response);
                  //how do i include my table code (attached above) here

            },
            failure: function (response) {
                return; 
            },
            error: function (response) {
                return;
            }
        });
});

I put an alert to make sure I am getting questions and answers in the ajax response. I should now display both questions and answers in the table on button click like its happening on page load. This has to be done in Ajax call after success response. I am new to Ajax, can anyone help me on this? How can I loop my repsonse and display in a format attached.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
    • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
    • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
    • ¥30 3天&7天&&15天&销量如何统计同一行
    • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
    • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
    • ¥15 vs2019中数据导出问题
    • ¥20 云服务Linux系统TCP-MSS值修改?
    • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
    • ¥20 怎么在stm32门禁成品上增加查询记录功能