1

私の目的は、selectbox 値の strus2 アクションの変更を呼び出して、貸衣装 ID で顧客情報を表示することです。

私の問題は、json形式で値を取得するためにアクションクラスから何を返す必要があるかです

次のコードを試しましたが、何が問題なのかわかりません

    <script type="text/javascript">  
  $(function()
   {    alert("This function is calling, on change event of selectbox and customer id="+$(this).val());
     $("#customersjsonlstid").change(function(e)
         { 
                    $.ajax({
                        url: 'showCustomerInfoById.action',  //action name
                        data: "customerid=" + $(this).val(),    
                        dataType: "json",
                        success: function(data) {    

                            // Set the inputs from the json object , json output : {"price": "123.40", "distributor": "XYZ Inc."}          
                            $('#autocompleter_div_result1').val(data.distributor); //showing data on particular div
                            $('#autocompleter_div_result2').val(data.price);  //showing data on particular div
                        }
                    });
                });
    });             
</script>

選択ボックス:

                            <sj:select 
                                id="customersjsonlstid" 
                                name="editionType" 
                                href="%{customerJsonselecturl}" 
                                list="lstcust"
                                listValue="name" 
                                listKey="id"   
                                autocomplete="false"
                            />     
             <div id="autocompleter_div_result">`

struts.xml

        <action name="showCustomerInfoById" class="v.esoft.actions.customerdetails.CustomerSelectAction" method="CustomerdetailsById">
             <result name="success" type="json"/> 
        </action> 

アクションクラス

    public class CustomerSelectAction extends ActionSupport {

     private String  customerid;


//---------------------------------------------------------
   public String CustomerdetailsById()
    {
        System.out.print("--------Method called, customer id-----------"+customerid);
        return customerid;
    }
     //---------------------------------------------------------


public String getCustomerid() {
    return customerid;
}


public void setCustomerid(String customerid) {
    this.customerid = customerid;
}

  }
4

2 に答える 2

1

私は同じ問題に直面し、最終的に解決されました。あなたはこのように試すことができます:

$("#customersjsonlstid").change(function(e)
         { 
         var   customeridJson =    $('#customersjsonlstid').val();
                    $.ajax({
                        url: 'showCustomerInfoById',  //action name   same name in struts.xml
                        data: "customerid=" + customeridJson,    
                        dataType: "json",
                        async: true,
                        success: function(data) {    

                            // Set the inputs from the json object , json output : {"price": "123.40", "distributor": "XYZ Inc."}          
                            $('#autocompleter_div_result1').val(data.distributor); //showing data on particular div
                            $('#autocompleter_div_result2').val(data.price);  //showing data on particular div
                        }
                    });
                });
    }); 

私も同じことをしましたが、うまくいきました。これがあなたにとってもうまくいくことを願っています。

于 2014-11-11T15:16:28.187 に答える