404在控制台中处理ajax调用请求之后

时间:2017-09-06 08:07:45

标签: javascript json ajax spring-mvc drop-down-menu

我正在向控制器发出ajax调用GET请求,并且该方法正在处理但是在执行完成后。在网页控制台中显示404错误代码。

请找到以下代码进行ajax调用

jQuery(document).ready(function() {
  $.ajax({
    type: 'POST',
    dataType: 'json',
    contentType: "application/json",
    url: "${home}getOPList",
    cache: false,
    success: function(response) {
      //    var str = JSON.stringify(response);
      var operatorList;
      //         alert("yes");
      //         alert(str);

      for (var i = 0; i < response.length; i++) {
        console.log(response[i].listOfOperators);
        operatorList += "<option value =' " +
          response[i].sno +
          " '>" +
          response[i].listOfOperators +
          "</option>"

      }
      $('#opList').html(operatorList);

    },

    error: function() {
      alert('Error while request..');
    }
  });
  $("#opList").change(function() {
    var abc = document.getElementById('opList').value;
    alert("we got :: " + abc);
    $.ajax({
      type: 'GET',
      dataType: 'json',
      contentType: "application/json",
      url: "${home}partnerDetails?operator=" + abc,
      data: {
        operator: abc
      },
      cache: false,
      success: function(response) {
        //    var str = JSON.stringify(response);
        var partnerList;
        alert("yes");
        alert("oplist " + abc);

        for (var i = 0; i < response.length; i++) {
          console.log(response[i].campaignName);
          partnerList += "<option value =' " +
            response[i].sno +
            " '>" +
            response[i].campaignName +
            "</option>"

        }
        $('#ptList').html(partnerList);

      },

      error: function() {
        alert('Error while request in partners..');
      }
    });

  });
});

请找到控制器代码

@Controller
public class PartnerController {

Logger logger = Logger.getLogger(PartnerController.class.getName());
@Autowired
public UserService userService;

@Autowired
   public Gson gson;




public Gson getGson() {
    return gson;
}




public void setGson(Gson gson) {
    this.gson = gson;
}




public UserService getUserService() {
    return userService;
}




public void setUserService(UserService userService) {
    this.userService = userService;
}




 @RequestMapping(value ="/partnerDetails" , method=RequestMethod.GET)
 public String  getPartnerList(String operator){
    logger.info(" \t OP IN REQUEST :: "+operator);
    String partnerList = "";

    try{
     ArrayList<PartnersList> arrayList =     

(ArrayList<PartnersList>)userService.getPartnersListFromDB();
 logger.info(" \t PARTNERS LIST BEFORE CONVERSION :: "+arrayList);
     partnerList = gson.toJson(arrayList);
     logger.info(" \t PARTNERS LIST :: "+partnerList);

    }catch(Exception e){


        e.printStackTrace();
    }

    return partnerList;
}

}

我能够打印最后一个记录器和返回语句并且代码正在被执行,但有些我怎么也无法在网页上获取警报弹出窗口,最后一个警告是“我们得到”一个然后代码在控制器方法中得到处理,并在控制台中获得404如下所示,请帮助我。

 GET XHR http://localhost/Promotions/partnerDetails [HTTP/1.1 404 Not Found 40ms]

0 个答案:

没有答案