2

这里我写了对ajax响应对象的响应

protected void writeAjaxResponse(HttpServletRequest req 
                                 ,HttpServletResponse resp,String result){
        PrintWriter writer = null;
        try {
            writer = resp.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        writer.println(result);
        return;

    } 

后来我打电话

writeAjaxResponse(req, resp, "<p style=color:red>Error occured recording
                                                           your feedback!</p>");

在jQuery中

$.ajax({
                  type: 'POST',
                  url: 'savefeedback',
                  data: 'feedbacker='+feedbacker+'feedbackeremail=
                   '+feedbackeremail+'feedbacker='+feedbackermsg,
                  success:function(data){
                   alert(data); //here is the pin point


                    }
                });

但在警觉中我得到

    [object XMLDocument]

编辑:

这是我的servletdoPost()方法

@Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException { 

         String feedbacker = req.getParameter("feedbacker");
         String  feedbackeremail = req.getParameter("feedbackeremail");
         String  feedbackermsg = req.getParameter("feedbackermsg");

        boolean saveFeedback = MailSenderServlet.
            saveFeedback(req, resp, feedbackeremail, "",
                  feedbackermsg, feedbacker, feedbackeremail);
        if(saveFeedback){
            writeAjaxResponse(req, resp, "Feedback received succesfully!");
        }else{
            writeAjaxResponse(req, resp, "Error occured  !");
        }

    } 

但我期待我的回复信息。

如果我错过了什么,请告诉我。

请帮忙!!!!

4

1 回答 1

0

30 分钟研究后

我发现MIME type丢失并将我的方法更改为

protected void writeAjaxResponse(HttpServletRequest req 
                                 ,HttpServletResponse resp,String result){
       resp.setContentType("text/html;charset=UTF-8");
        PrintWriter writer = null;
        try {
            writer = resp.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        writer.println(result);
        return;

    }

感谢@Noob @ w4rumy @user2207792 的及时支持。

于 2013-05-07T10:46:05.773 回答