在Struts 2中使用jQuery JSON格式时无法呈现响应

时间:2013-03-22 07:30:56

标签: jquery jsp struts2 struts2-jquery struts2-json-plugin

我在加载select标记的响应时遇到问题。我正在尝试根据第一个更改选择框。

为此,我使用带有jQuery Ajax标签的Struts2。我想我已经完成了所有需要的东西,但响应没有标记到选项但能够在浏览器的视图源的JS中看到结果.Below是我在JSP中编写的代码 这是我的第一个选择框

<div class="type-text">
  <s:url id="remoteurl" action="getGlobalManufacturerJquery.action?mainId=title&subId=Add Title&selectedManufacturer=strUser&gameFileID=%{gameFileID}&gameFileName=%{gameFileName}&titleName=%{titleName}&titleID=%{titleID}"/>
                <sj:select 
                    href="%{remoteurl}" 
                    formIds="TitleGameHandsetsForm"
                    id="manufacturerName%{titleGameFilemappingID}" 
                    onChangeTopics="reloadsecondlist" 
                     name="manufacturerName%{titleGameFilemappingID}"
                    list="%{manufacturers}" 
                     listKey="%{globalManufacturer}"

                    listValue="%{globalManufacturer}" 
                    emptyOption="true" 
                    headerKey="-1" 
                    headerValue="Select Global Manufacturer" 
                />
          </div>

以下是我的第二个选择框,它应该是第一个值

 <div class="type-text">        
                 <s:url id="remoteurl" action="getGlobalModelJquery.action?mainId=title&subId=Add Title&selectedManufacturer=strUser&gameFileID=%{gameFileID}&gameFileName=%{gameFileName}&titleName=%{titleName}&titleID=%{titleID}"/>
                <sj:select 

                    id="globalModel%{titleGameFilemappingID}" 
                    formIds="TitleGameHandsetsForm" 
                    reloadTopics="reloadsecondlist" 
                    name="modelFromSelect" 
                    list="%{modelList}" 
                    emptyOption="true" 
                    headerKey="-1" 
                    headerValue="Select Global Model"
                />
                </div>

在jsp中没有可用的列表。但是服务器代码得到的结果我可以在js的源代码中看到,它无法附加到选择框的jsp。

<select name="manufacturerName77" id="manufacturerName77">
<option value=""></option>
</select>
<script type='text/javascript'>
jQuery(document).ready(function () {
    var options_manufacturerName77 = {};
    options_manufacturerName77.datatype = "json";
    options_manufacturerName77.type = 'select';
    options_manufacturerName77.emptyoption = true;
    options_manufacturerName77.headerkey = "-1";
    options_manufacturerName77.headervalue = "Select Global Manufacturer";
    **options_manufacturerName77.list = "[Acer, A Panda]";**
    options_manufacturerName77.listkey = "Acer";
    options_manufacturerName77.listvalue = "Acer";
    options_manufacturerName77.jqueryaction = "select";
    options_manufacturerName77.id = "manufacturerName77";
    options_manufacturerName77.name = "manufacturerName77";
    options_manufacturerName77.oncha = "reloadsecondlist";
    options_manufacturerName77.href = "/ci/getGlobalManufacturerJquery.action";
    options_manufacturerName77.hrefparameter = "mainId=title&subId=Add Title&selectedManufacturer=strUser&gameFileID=3&gameFileName=dcdscd&titleName=Bubble boom chalenge&titleID=11";
    options_manufacturerName77.formids = "TitleGameHandsetsForm";


jQuery.struts2_jquery.bind(jQuery('#manufacturerName77'),options_manufacturerName77);

 });
</script>
          </div>

1 个答案:

答案 0 :(得分:0)

如果错误地写入了url,那么应返回列表的json数据的操作将不会返回任何内容。你应该写一下像

这样的网址
<s:url var="remoteurl" action="getGlobalManufacturerJquery">
  <s:param name="mainId" value="title"/>
  <s:param name="subId" value="Add Title"/>
  <s:param name="selectedManufacturer" value="strUser"/>
  <s:param name="gameFileID" value="%{gameFileID}"/>
  <s:param name="gameFileName" value="%{gameFileName}"/>
  <s:param name="titleName" value="%{titleName}"/>
  <s:param name="titleID" value="%{titleID}"/>
</s:url>