簡體   English   中英

Ajax響應作為映射對象綁定到HTML

[英]Ajax response as Map Object to bind to Html

我將結果數據集設置為Map Object 我正在使用下面的腳本將數據附加到HTML。 但這並沒有影響。

$("#district").change(
        function() {
            $('#mandal').html('');
            var district = {
                "district" : $("#district").val()
            };
            $.ajax({
                url : "Reports",
                data : JSON.stringify(district),
                dataType : 'json',
                contentType : 'application/json',
                type : 'POST',
                async : true,
                success : function(res) {
                    console.log(res.resList.length);
                    for ( var i = 0; i < res.resList.length; i++) {
                        console.log("Kalishavali " + res.resList[i]);
                        $('#mandal').append(
                                '<option value=' + res.resList[i] + '>'
                                        + res.resList[i]
                                        + '</option>');
                    }
                }
            });
        });

結果數據格式:

{08=Prakasam, 09=S.P.S Nellore, 04=East Godavari, 05=West Godavari, 06=Krishna, 07=Guntur, 13=Kurnool, 01=Srikakulam, 11=Kadapa, 02=Vizianagaram, 12=Anantapur, 03=Visakhapatnam, 10=Chittoor}

這是我的Jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@include file="includes/Header_1.html" %>
<script>
$(function() {
$("#district").change(
        function() {
            $('#mandal').html('');
            var district = {
                "district" : $("#district").val()
            };
            $.ajax({
                url : "Reports",
                data : JSON.stringify(district),
                dataType : 'json',
                contentType : 'application/json',
                type : 'POST',
                async : true,
                success : function(res) {
                    console.log(res.resList.length);
                    for ( var i = 0; i < res.resList.length; i++) {
                        console.log("Kalishavali " + res.resList[i]);
                        $('#mandal').append(
                                '<option value=' + res.resList[i] + '>'
                                        + res.resList[i]
                                        + '</option>');
                    }
                }
            });
        });
});
</script>


         <s:select label="District" list="resList" listKey="key" value="value" name="district" headerKey="-1" headerValue="Select District"/>
         Mandal :
    <select id="mandal"></select>

響應無效JSON:

  1. 鍵值對用=代替,而不是:
  2. 他們周圍沒有報價

應該 :

{"08" : "Prakasam", "09" : "S.P.S Nellore" etc...}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM