473,320 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ajax with servlet

I am trying to call a servlet i created. Basically this servlet
will let user create a new account at the server.
I have created the function "CreateAccount()" but
http_request.readyState always return me 0

What is wrong with my code?

function CreateAccount()
{
if( window.XMLHttpRequest )
{
http_request = new XMLHttpRequest();
}
else if( window.ActiveXObject )
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
var parameters = "username=" + encodeURI(
document.getElementById("username").value ) +
"&password=" + encodeURI(
document.getElementById("password").value );

http_request.onreadystatechange = RegisterUser();
http_request.open('post', "/servlet/CreateUserAccount", true );
http_request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);

}
}

function RegisterUser()
{
alert( "register user: " + http_request.readyState );
if( http_request.readyState == 4 )
{
if( http_request.status == 200 )
{
alert( http_request.responseText );
}
else
{

}
}
}

Dec 10 '05 #1
3 10913

Shinya Koizumi wrote:
http_request.onreadystatechange = RegisterUser();


You are assigning the return value of the function call to
RegisterUser(). You should be assigning a function reference instead:

http_request.onreadystatchange = RegisterUser;

Dec 10 '05 #2
Thanks it solved the previous problem
However, it takes about 10 seconds to get the response.
Do you happen to know why?
"web.dev" <we********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

Shinya Koizumi wrote:
http_request.onreadystatechange = RegisterUser();


You are assigning the return value of the function call to
RegisterUser(). You should be assigning a function reference instead:

http_request.onreadystatchange = RegisterUser;

Dec 12 '05 #3
How long does it take to get a response if you call it
from an ordinary form, or browse to it manually?

--
Dag.

"Shinya" <xx*@smartestdesign.com> wrote in message
news:lcknf.159663$yS6.113623@clgrps12...
Thanks it solved the previous problem
However, it takes about 10 seconds to get the response.
Do you happen to know why?
"web.dev" <we********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

Shinya Koizumi wrote:
> http_request.onreadystatechange = RegisterUser();


You are assigning the return value of the function call to
RegisterUser(). You should be assigning a function reference instead:

http_request.onreadystatchange = RegisterUser;


Dec 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Frances | last post by:
I literally started learning AJAX just last weekend.. I have this page, http://www.francesdelrio.com/ajax/db2.html, where I'm essentially doing what's here,...
1
nmm32
by: nmm32 | last post by:
I am trying to use Ajax with JSP to populate a 2nd drop down list based on the chosen option of the first one. I am getting the error "Object Expected" on the line 13-14 of the HTML: <script...
2
by: archanagp | last post by:
Hi, I am trying to develop a portlet which has a javascript function which uses ajax to call a servlet in the server. The portlet I am trying to develop is in websphere application developer. My...
6
by: santhoskumara | last post by:
How to request to servlet from Ajax and also I got the DOM object in the servlet through Business Logic. Now how will i pass the DOM object from serlvet to Clientside. Where in the client Side i am...
3
by: nnaveenraju | last post by:
Hi Gurus, I am new to Ajax and JAVA. I am able to call the servlet class from the JSP page using AJAX. The servlet class is called successfully. I am processing some data and the data has...
1
by: galdunne | last post by:
Hi, Im new to ajax and im using prototype for a project i am working on. I am hoping to call a servlet written in java which holds a hashtable to strings. When i click on a link it opens up a tab...
1
sid0404
by: sid0404 | last post by:
Hi I need to send data from my servlet to my html(which contains AJAX), so as per the motivation of the AJAX, this should be done without my webpage reloading / refresh. my code on the ajax...
3
by: rbansalit | last post by:
Hi all I am making a very simple ajax call. But I am not getting any message from sever. <html> <body> <script type="text/javascript"> function ajaxFunction()
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.