【问题标题】:returning error response in jquery在 jquery 中返回错误响应
【发布时间】:2016-10-29 01:20:31
【问题描述】:

我正在尝试从 jquery 调用控制器。这里一切正常,但在 ajax 中它显示错误警报。出了什么问题。

$.ajax({
                         type: 'POST',
                         url:'<%=request.getContextPath()%>/billing',
                         data: ({caseId: caseId,  noteID :  noteID}),    
                         cache: false,
                         success: function(data){
                                alert("Success");
                            },
                         error: function(xhr, textStatus, error){
                         alert("Error occured.");
                         }
                         });

我的控制器

@RequestMapping(value = "/billing", method = RequestMethod.POST)
    public String Billing(@RequestParam Long caseId,
            @RequestParam Long noteID, HttpServletRequest request)  throws Exception {
        try{

           ----Some data base updation---
            logger.debug("success ");
        return "success";
        } catch (Exception e) {
            logger.error(e,e);
            throw e;
        }}

请帮帮我。

【问题讨论】:

  • 尝试检查错误回调中的 textStatus,error 参数,这些参数将为您提供更多信息。另外我建议您也检查服务器日志。
  • 在传递数据时,data: ({caseId: caseId, noteID : noteID}) 中确实不需要圆括号。请删除它们(以( 开头并以) 结尾),您将不会收到任何错误。
  • 检查this

标签: java jquery ajax jsp


【解决方案1】:

//你必须留下内容类型发送服务器端,请定义内容类型..

 $.ajax({
                type: "POST",
                url: '@Url.Action("PerTGradeMastEdit", "Master")',
                data: "{'Request':'" + request + "'}",
                contentType: "application/json; charset=utf-8",
                success: function (response) {
                    if (response != null) {

                        var strResponse = response;
                        var ProgramData = strResponse.split("/");
                        // response = ProgramData[0];programId
                        $('#txtPerGrade').val(ProgramData[0]);
                        $('#txtDesc').val(ProgramData[1]);

                    }
                },
                failure: function (msg) {
                    alert(msg);
                    window.location.href = '@Url.Action("INDEX", "AUTHORIZE")';
                }
            });`enter code here`

【讨论】:

    猜你喜欢
    • 2019-05-26
    • 2011-03-27
    • 2014-09-15
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    • 2019-09-30
    • 2011-02-24
    相关资源
    最近更新 更多