簡體   English   中英

Ajax Jquery Post呼叫進入400(錯誤請求)

[英]Ajax Jquery Post call getting into 400 (Bad Request)

我正在嘗試使用jquery來實現ajax調用。提交請求時,它會拋出400錯誤請求。.不確定我的ajax調用在哪里做錯了。需要幫助解決此問題。

submitHandler:function(form){
        var emailSub = $("#emailSubTxtArea").val();
        var emailBody = $("#emailBodyTxtArea").val();
        if(confirm("You are about to send Email Communication, Are you sure..?")){
        $.ajax({
            type: "POST",
            url:  $("#applicationUrl").val() +"/web/utilities/sendEmailMessage",
            dataType: "json",
            //cache:false,
            contentType: "application/json; charset=utf-8",
            data:JSON.stringify({emailSubject : emailSub,emailMsg : emailBody}), 
            success:function(data)
            {
                console.log("Sending Email Notification was success.");
            },
            error: function(x, t, m) {
                console.trace();
                if (!(console == 'undefined')) {
                console.log("ERROR: " + x + t
                        + m);
                }
                }
       });
    }

我的控制器代碼:

 @RequestMapping(value="/sendEmailMessage",method=RequestMethod.POST)
    public ModelAndView sendEmailCommunication(@RequestParam("emailSubject") String emailSubject,@RequestParam("emailMsg") String emailBody,HttpServletRequest request){
        ModelAndView view = null;
        StringBuffer sMsg = new StringBuffer();
        StringBuffer eMsg = new StringBuffer();
        boolean isAdmin = false;
        try{
        String loggedInUser = request.getHeader("sm_user").trim();
         isAdmin = getUserAdminRights(request);
        if(isAdmin){
            boolean status = emailService.sendEmailCommuncation(emailSubject,emailBody);
            if(status){
                sMsg.append(" Sending SiteMinder Notification Email was Success.");
            }
            else{
                eMsg.append(" Oops! Something went wrong while sending Email Notification. Pls check logs");
            }
        }
        else{
             view = new ModelAndView("redirect:/web/utilities/not_authorized");
             return view;
        }
        }
        catch(Exception ex){
            ex.printStackTrace();
            eMsg.append("Oops! Something went wrong while sending Email Notification. Pls check logs");
        }
        view = new ModelAndView("EmailCommunication");
        view.addObject("isAdmin", isAdmin);
        view.addObject("sMsg", sMsg.toString());
        view.addObject("eMsg", eMsg.toString());
        return view;
    }

大家好...

很簡單

submitHandler:function(form){

        if(confirm("You are about to send Email Communication, Are you sure..?")){
        $.ajax({
            type: "POST",
            url:  $("#applicationUrl").val() +"/web/utilities/sendEmailMessage",            
            data:$(form).serializeArray(), 
            success:function(data)
            {
                console.log("Sending Email Notification was success.");
            },
            error: function(x, t, m) {
                console.trace();
                if (!(console == 'undefined')) {
                console.log("ERROR: " + x + t
                        + m);
                }
                }
       });
    }
var strResponse=$.ajax({ type: "POST", url:  $("#applicationUrl").val() +"/web/utilities/sendEmailMessage",
 data: JSON.stringify({emailSubject : emailSub,emailMsg : emailBody}), async: false, 
 contentType: "application/json; 
 charset=utf-8", dataType: "json" });
 if (strResponse.readyState == 4 && strResponse.status == 200)
            return ((strResponse.responseText.indexOf("d") >= 0) ? eval('(' + strResponse.responseText + ')').d : strResponse.responseText);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM