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 8165539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:33:57+00:00 2026-06-06T19:33:57+00:00

I am very new to ajax concept,I want to submit a form without refresh

  • 0

I am very new to ajax concept,I want to submit a form without refresh the page

ajax

function ajaxFunction() {
  if(xmlhttp) { 
   var txtname = document.getElementById("txtname");
    xmlhttp.open("POST","Listservlet",true);
    xmlhttp.onreadystatechange  = handleServerResponse;
    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlhttp.send("txtname=" + txtname.value);
  }
}

function handleServerResponse() {
   if (xmlhttp.readyState == 4) {
     if(xmlhttp.status == 200) {
       document.fname.message.innerHTML=xmlhttp.responseText;
     }
     else {
        alert("Error during AJAX call. Please try again");
     }
   }
}

JSP

<form name="fname" action="Listservlet" method="post">
<input type="text" name="txtname" id="txtname" />
<input type="button" value="Submit"  onclick="ajaxFunction();" />
<div id="message"></div>
</form>

servlet

public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
  String name = null;
  PrintWriter out = response.getWriter();
  if(request.getParameter("txtname") != null) {
   name = request.getParameter("txtname");
  }
                else {
                       name = "";
                }
           out.println("You have successfully made Ajax Call:" + name);
 }

This ajax idea I got from google, bt it is not working,
While clicking on the button,nothing it showing.
Please help me.

  • 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-06T19:33:59+00:00Added an answer on June 6, 2026 at 7:33 pm

    replace

     document.fname.message.innerHTML=xmlhttp.responseText;
    

    by

    document.getElementById("message").innerHTML=xmlhttp.responseText;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Feeling very proud of myself after creating a form with an AJAX submit, I
I am very new to Ajax technique Is there any site or online documents
I am very new to ajax and jquery but I know some php. I
I am very new to javascript and ajax/jquery and have been working on trying
I'm very new to jQuery, Ajax and things like these. I've found solutions on
I'm very new at AJAX calls from jQuery and I'm a bit stuck trying
Hey guys, I am very new to AJAX and and working on a rating
I'm very new to the whole Ajax/Asp.Net stuff so... I know that there are
I am very new to ajax and jquery, but I came across a code
I am very new to Ajax and I'm trying to show the completed task

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.