Announcement Announcement Module
Collapse
No announcement yet.
Ajax jquery error while getting respose as list as a data in spring mvc Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ajax jquery error while getting respose as list as a data in spring mvc

    I am new to ajax call in jquery and facing some issue. Below is the detail description:
    I have two drop down in my jsp one is for country selection and another is for State selection. I want to populate my state drop down based on the country selection. But my state data is not getting populated based on the country selection. Below is my jsp code:


    Code:
    ---------
    --------
        <tr>
                <th><f:label path="country">
    
                        <s:message code="label.storecountry"></s:message>
                    </f:label>
                </th>
                <td><f:select path="country" multiple="false" name="country"
                        id="country" onchange="javascript:setcountry(country)">
                        <f:option value="0" label="please Select country" size="40" />
                        <c:forEach items="${countries}" var="prospect">
                            <f:option value="${prospect.countriesId}">
                                <c:forEach items="${prospect.countriesDescriptions}" end="0"
                                    var="prospect1">
                                    <c:out value="${prospect1.countriesName}" />
                                </c:forEach>
                            </f:option>
                        </c:forEach>
                    </f:select>
                </td>
            </tr>
    
        <tr>
                <th><f:label path="zones" id="zoneslable">
    
                        <s:message code="label.storezone"></s:message>
                    </f:label></th>
    
                <td><div id="zonesdiv">
                        <f:select path="zones" multiple="false">
                            <f:option value="0" label="please Select State" size="40" />
                            <c:forEach items="${zones}" var="prospect">
                                <f:option value="${prospect.zoneCode}">
                                    <c:forEach items="${prospect.zonesDescriptions}" end="0"
                                        var="prospect1">
                                        <c:out value="${prospect1.zoneName}" />
                                    </c:forEach>
                                </f:option>
                            </c:forEach>
                        </f:select>
                    </div></td>
            </tr>
    -------------

    below is my ajax function code:

    Code:
     <script type='text/javascript'>
    
    function setcountry(country) {
    
    var country1 = document.getElementById('country').value;
    
     jQuery.ajax({
    
    url:"/paradigamaticweb/list",
    
      type:"GET",
    
     datatype:"json",
    
    data:{country : country1},
    
     success: function(data,textStatus)
         {  
    
         jQuery("#zonesdiv").html(data);
    
         },
         error: function(e,textStatus, errorThrown)
         {
             alert('Error: ' + textStatus);     
         }
          });
    Below is my controller :
    Code:
    public class MarchentController
    {
    @RequestMapping(value="/list",method = RequestMethod.GET)
        public @ResponseBody List addStatelist( Model model,HttpServletRequest request, HttpServletResponse response)
    
        {
            //String countryid=null;
            String countryid1=request.getParameter("country");
            int countryid=Integer.parseInt(countryid1);
    
    
    
            List zonelist=countryListCntroller.AjaxzoneList(countryid);
            //countryListCntroller.showStateList(model);
            Set zone=null;
            Iterator< Zones> it=zonelist.iterator();
            while(it.hasNext())
            {
            Zones zone1=it.next();
            zone=zone1.getZonesDescriptions();
            }
            String zonename=null;
    Iterator  it1=zone.iterator();
            while(it1.hasNext())
            {
                ZonesDescription zone2= (ZonesDescription) it1.next();
                zonename=zone2.getZoneName();
            }
            List list=new ArrayList<Zones>();
            list.add(zonename);
    
        model.addAllAttributes(list);
    
            //countryListCntroller.showOrderList(model);
            return list;
    
        }
    
    }

    Below the response body which I am getting as an error in browser:

    /7.0.23 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 406 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.23</h3></body></html>`
    org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.http.converter.json.MappingJac ksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.codehaus.jackson.type.JavaType.<init>(Ljava/lang/Class`
    I have also add two jar file in my class path related to JSON.
    "jackson-core-asl-1.9.7.jar and
    jackson-mapper-asl-1.9.6.jar"

    Also i have added below code in my spring ´┐Żservlet.XML.

    Code:
    <bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"></bean>

    But after these changes, I am getting below error :

    `Error creating bean with name 'jsonConverter' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.http.converter.json.MappingJac ksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.codehaus.jackson.type.JavaType.<init>(Ljava/lang/Class`
    Please let me know how to proceed? What is the meaning of above configuration in spring file? Is it necessary for ajax call in json format? Any pointer in this regard will be very helpful. Thanks in advance. Please let me know if any other information is required.

    Thanks, Vikas
Working...
X