Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8852105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:19:05+00:00 2026-06-14T13:19:05+00:00

We have a JavaServlet running which provides us with needed data. The problem is

  • 0

We have a JavaServlet running which provides us with needed data. The problem is the way Jquery interprets this data.

Information is sent through the response writer. (Eg: messages)

protected void doPost(HttpServletRequest request,
    HttpServletResponse response)
        throws ServletException {

    String body = "";
    for (Message msg : messages) {
        body += "<div class=\"Message\" id=\"" + msg.getId() + "\">"
            + *inner information*
            + "</div>";
    }
    response.getWriter().write(body);
}

The information is gotten through Ajax requests

$.ajax({
    type: 'POST',
    url: 'message.jsp',
    data: { *Needed data* },
    success: function(data) {
        $('#element').append(data);
    }
});

This sometimes works and sometimes it does not. So we checked the console in chrome and let the code stop at the append line. When multiple messages are sent the ‘data’ in the success function is interpreted as a big string,

"<div class="message" id="153" onclick="loadFullMessage(153)"></div>
<div class="message" id="154" onclick="loadFullMessage(154)"></div>
<div class="message" id="155" onclick="loadFullMessage(155)"></div>
<div class="message" id="156" onclick="loadFullMessage(156)"></div>
"

but when only 1 message/div is send it is interpreted as a ‘#document’ object.

#document
    <div class=​"message" id=​"174" onclick=​"loadFullMessage(174)​">​…​</div>​

The message is available as can be seen in chrome console, but when appending the following error is encountered ‘Uncaught Error: HIERARCHY_REQUEST_ERR: DOM Exception 3’.

How can the data just always be interpreted as a string and not change into the document object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:19:06+00:00Added an answer on June 14, 2026 at 1:19 pm

    @boblail is right – changing dataType to ajax will make it. However, you sometimes use third party libraries that you are not going to modify. It’s JQuery UI in my case.

    Sending Content-Type: application/xhtml+xml causes JQuery to build a DOM Document out of the response. Set your Content-Type to text/html and you are fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem figuring this out the right way. I have a
I have a Java Servlet, which is handling a REST request. However, this is
I have this java servlet that grabs information from a form, I need to
have written this little class, which generates a UUID every time an object of
I have an HTML form which posts its information to a java servlet. One
I have a legacy Java servlet that is currently running in a Tomcat container.
I have a Java servlet that receives data from an upstream system via a
I have a Java servlet which calls another software (say S) over a TCP
I have a Java servlet from which I need to send few notifications to
I have a java servlet which accepts an image a user uploads to my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.