如何在spring mvc中从ajax请求调用控制器?

时间:2016-08-02 11:50:49

标签: javascript jquery ajax spring

$.ajax({
        type : "POST",
        url : "${pageContext.request.contextPath}/saveWorkingHours",
        data : "campaignWorkingHours="+JSON.stringify(campaignWorkingHours),
        async: false,    
        cache: false,              
        success : function(response) {

            $.ajax({
                 type: "GET",
                 url: "${pageContext.request.contextPath}/jobSchedule"
                });

        }, 
        error : function() {
            alert("error");
        }
});

我有以下控制器方法:

// For handling job schedule page request
@RequestMapping(value = "jobSchedule", method = RequestMethod.GET)
public ModelAndView jobSchedule() {

    ModelAndView workingHoursModel = new ModelAndView(
            Constants.CAMPAIGNWORKINGHOURS);

    try {

        // Get campaigns
        List<Object[]> lstCampaigns = CommonUtil.castList(Object[].class,
                objCommonService.getCampaigns());

        workingHoursModel.addObject("Campaigns", lstCampaigns);

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }

    return workingHoursModel;
}

从控制器的saveWorkingHours方法获得成功响应,但是作业调度方法没有得到执行。以下错误:

  

获取http://localhost:8081/CampaignDesigner/jobSchedule 0ms jquery -.... min.js(第4行)   “NetworkError:405方法不允许 - http://localhost:8081/CampaignDesigner/jobSchedule

0 个答案:

没有答案