春天mvc ajax json有时畸形

时间:2017-02-02 07:17:28

标签: java jquery json ajax spring

使用的库

  1. spring.4.3.4 jar
  2. jquery 1.9.1
  3. gson-2.2.2 jar
  4. 使用JDBCTemplate

    控制器

    @RequestMapping(value = "user/getApmcBudgTransData", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
        public @ResponseBody String getUserLevelMasterDetails(HttpServletRequest request,HttpServletResponse res) { 
            ModelAndView model = new ModelAndView();
            String yrmstid=request.getParameter("finyrMstid");
            String apmcid=request.getParameter("apmcid");
            String sendToOfc = request.getParameter("sendToOfc");   
            String opFlag = request.getParameter("opFlag"); 
            String formType = request.getParameter("formType"); 
            ArrayList<ApmcBudgTransaction> apmcBudgtrandata=budgetService.getApmcBudgTransData(apmcid, yrmstid, sendToOfc, opFlag, formType);       
    
            Gson gson = new Gson();
            return gson.toJson(apmcBudgtrandata);
        }
    

    JSP ajax调用

                      $.ajax({
                        url:"${pageContext.request.contextPath}/user/getApmcBudgTransData",
                        type:'post',  
                        dataType: 'json',
                        async:false,
                        data: {
                            finyrMstid :lastyr,
                            apmcid : pkvalue,
                            sendToOfc : "APMC",
                            opFlag : flag,
                            formType : "S"
                         },
                       success: function(resp) {},
                       error: function(err) {}
    
                       });
    

    弹簧servlet.xml中

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans     
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/util 
           http://www.springframework.org/schema/util/spring-util-2.5.xsd">
    
        <context:component-scan base-package="com.me.you" />
    
        <context:annotation-config />
    
        <mvc:annotation-driven />
        <mvc:default-servlet-handler />
    
    
        <mvc:interceptors>
    
    
        <bean id="webContentInterceptor" 
              class="org.springframework.web.servlet.mvc.WebContentInterceptor">
            <property name="cacheSeconds" value="0"/>
            <property name="useExpiresHeader" value="true"/>
            <property name="useCacheControlHeader" value="true"/>
            <property name="useCacheControlNoStore" value="true"/>
        </bean>
        </mvc:interceptors>
    
    
        <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/view/" />
            <property name="suffix" value=".jsp" />
        </bean>
    
    
    
    </beans>    
    

    ajax调用正在从控制器接收大量的utf-8 json数据。

    json在控制器中每次都很好。

    当控件返回到ajax调用时,第一次,json格式错误并调用错误函数。

    第二次以及随后的每一次,json都处于良好状态,并且调用了成功函数。

    Firebug截图

    http://imgur.com/a/eHb5s

    格式错误的json

       [
      {
        "finYrID": "3",
        "budgetTransId": "18127210",
        "operationId": "",
        "commonTrno": "165",
        "suppliBudgYn": "N",
        "tranDate": "10/05/2016",
        "srNo": "1",
        "apmcGlMstId": "1",
        "apmcMstId": "165",
        "lastYrActualAmt": "2741406",
        "currYrActualAmt": "2562",
        "currYrExpAmt": "0",
        "currYrTotExpAmt": "2562",
        "apmcCurrBudgAmt": "2379",
        "disCurrBudgAmt": "2379",
        "divCurrBudgAmt": "2379",
        "apmcRemark": "",
        "distRemark": "",
        "divRemark": "",
        "msambRemark": "शिफारस आहे",
        "sanctionRemark": "",
        "suppBudAmt": "0",
        "suppDistBudgAmount": "",
        "suppDivBudgAmount": "",
        "suppHoBudgetAmt": "",
        "suppBudgetRemark": "",
        "suppDisRemark": "",
        "suppDivRemark": "",
        "suppHoRemark": "",
        "suppSancRemark": "",
        "printPosition": "",
        "forwardStatus": "P",
        "lastYrBudgamt": "3035810",
        "msambCurYrBudgAmt": "2379",
        "glName": "सुरवातीची रोख शिल्लक ",
        "abrxFlg": "INCOME",
        "parentId": "",
        "allowEntry": "Y",
        "apmcTranDate": "12/05/2016",
        "distTranDate": "24/05/2016",
        "divTranDate": "06/06/2016",
        "hoTranDate": "19/07/2016",
        "sanctionDate": "20/09/2016",
        "docAppFlag": "",
        "suppBudgTrno": "100165",
        "apmcSuppTranDate": "",
        "distSuppTranDate": "",
        "divSuppTranDate": "",
        "hoSuppTranDate": "",
        "sancSuppDate": "",
        "suppDocAppFlag": "Y",
        "budgSendToOffice": "SANCTION",
        "suppSendToOffice": "APMC",
        "suppCurYrActualAmt": "2379",
        "suppCurYrExpectedAmt": "0",
        "suppCurYrTotExpectedAmt": "2379"
      },
      {
        "finYrID": "3",
        "budgetTransId": "18127209",
        "operationId": "",
        "commonTrno": "165",
        "suppliBudgYn": "N",
        "tranDate": "10/05/2016",
        "srNo": "181",
        "apmcGlMstId": "181",
        "apmcMstId": "165",
        "lastYrActualAmt": "0",
        "currYrActualAmt": "0",
        "currYrExpAmt": "304852",
        "currYrTotExpAmt": "304852",
        "apmcCurrBudgAmt": "438307",
        "disCurrBudgAmt": "1238307",
        "divCurrBudgAmt": "1148307",
        "apmcRemark": "",
        "distRemark": "898751.00",
        "divRemark": "",
        "msambRemark": "",
        "sanctionRemark": "",
        "suppBudAmt": "315514",
        "suppDistBudgAmount": "0",
        "suppDivBudgAmount": "0",
        "suppHoBudgetAmt": "0",
        "suppBudgetRemark": "",
        "suppDisRemark": "",
        "suppDivRemark": "",
        "suppHoRemark": "",
        "suppSancRemark": "",
        "printPosition": "",
        "forwardStatus": "P",
        "lastYrBudgamt": "0",
        "msambCurYrBudgAmt": "898751",
        "glName": "अखेरची बँक शिल्लक ",
        "abrxFlg": "EXPENSES",
        "parentId": "",
        "allowEntry": "Y",
        "apmcTranDate": "12/05/2016",
        "distTranDate": "24/05/2016",
        "divTranDate": "06/06/2016",
        "hoTranDate": "19/07/2016",
        "sanctionDate": "20/09/2016",
        "docAppFlag": "",
        "suppBudgTrno": "100165",
        "apmcSuppTranDate": "",
        "distSuppTranDate": "",
        "divSuppTranDate": "",
        "hoSuppTranDate": "",
        "sancSuppDate": "",
        "suppDocAppFlag": "Y",
        "budgSendToOffice": "SANCTION",
        "suppSendToOffice": "APMC",
        "suppCurYrActualAmt": "957593",
        "suppCurYrExpectedAmt": "",
        "suppCurYrTotExpectedAmt": "957593"
      }
    ]
    

    我不能因为喜欢编程而弄清楚为什么会这样。

0 个答案:

没有答案