473,785 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get null response

7 New Member
hi
This my ajax code
[HTML]<html>
<head>
<script type="text/javascript">
var req=null;
var console=null;
function sendRequest(url ,HttpMethod)
{
if (!HttpMethod)
{
HttpMethod="GET ";
}
req=initXMLHTTP Request();
if (req)
{
req.onreadystat echange=onReady State;
req.open(HttpMe thod,url,true);
req.send(null);
}
}
function initXMLHTTPRequ est()
{
var xRequest=null;
if (window.XMLHttp Request)
{
xRequest=new XMLHttpRequest( );
}
else if (window.ActiveX Object)
{
xRequest=new ActiveXObject
("Microsoft.XML HTTP");
}
return xRequest;
}
function onReadyState()
{
var ready=req.ready State;
var data=null;
if (ready==4)
{
if(req.status== 200)
data=req.respon seText;
}
else
{
data="loading.. .["+ready+"]";
}
toConsole(data) ;
}
function toConsole(data)
{
if (console!=null)
{
var newline=documen t.createElement ("div");
console.appendC hild(newline);
var txt=document.cr eateTextNode(da ta);
newline.appendC hild(txt);
//console.innerHT ML=data;
}
}
function abc()
{
console=documen t.getElementByI d("console");
sendRequest("aj ax2.jsp?name="+ encodeURICompon ent(user.value) );
}
</script>
</head>
<body>
<p>
<input type="text" value="" name="user" onchange="javas cript:abc()"></p>
<div id="console"></div>

</body>
</html>[/HTML]



& this is my jsp code
Expand|Select|Wrap|Line Numbers
  1. <%
  2. response.setContentType("text/html");
  3. response.setHeader("Cache-Control","no-Cache");
  4. response.getWriter().write(=request.getParameter("user"));
  5. response.getWriter().write("Tejashri");
  6. %>
After browsing It should display
Whatever text is entered in text field & then Tejashri
But it gives sometimes "null", sometimes "Tejashri", sometimes some other combination
Please check this code If u fill it is wrong please intinate me or correct that code
thanks in advance
Mar 16 '08 #1
11 3516
gits
5,390 Recognized Expert Moderator Expert
may be the request.status doesn't get to 200? in that case you will get a null value (as you programmed it :: data = null) ... may be the request is aborted?

kind regards
Mar 16 '08 #2
jomshri
7 New Member
hi thanks for help
but please tell me what should I do now.
My project get stuck on this point


please please help me
Thanks in advance
Mar 17 '08 #3
gits
5,390 Recognized Expert Moderator Expert
do you use your glaobal request object for other requests too? you could use a mechanism that avoids to send a new request before you got the response from the already started one or you may use a local request variable.

kind regards
Mar 17 '08 #4
jomshri
7 New Member
hi Gits
thanks for ur quick reply everytime.
Let me know ,what is the tomcat_home path in Environment variable.
Where should we place Tools.jar file in tomcat folder
Please give ans in detail
I am new to Tomcat,JS
So please help me
I hope This time also u reply me as soon as possible
--thanks
Mar 18 '08 #5
jomshri
7 New Member
Actually It is not working yet.
What should I do for that please suggest me something
Again I am sending my code please check it carefully & let me know what r the errors in that code.

HTML CODE
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="simple.js">
  4. </script>
  5. </head>
  6. <body>
  7. <p>
  8. <input type="text" name="name" value="" onchange = abc()>
  9. <div id="simple_div"></div></p>
  10. </body>
  11. </html>
  12.  
Javascript CODE
Expand|Select|Wrap|Line Numbers
  1.  var req=null;
  2. var console=null;
  3. function sendRequest(url,HttpMethod)
  4. {    
  5.     if (!HttpMethod)
  6.     {
  7.         HttpMethod="GET";
  8.     }
  9.     req=initXMLHTTPRequest();
  10.     if (req)
  11.     {
  12.         req.open(HttpMethod,url,true);
  13.         req.onreadystatechange=onReadyState;
  14.         req.send(null);
  15.     }
  16. }
  17. function initXMLHTTPRequest()
  18. {
  19.     var xRequest=null;
  20.     if (window.XMLHttpRequest)
  21.     {
  22.     xRequest=new XMLHttpRequest();
  23.     } 
  24.     else if (window.ActiveXObject)
  25.     {
  26.     xRequest=new ActiveXObject("Microsoft.XMLHTTP");
  27.     }
  28.     return xRequest;
  29. }
  30. function onReadyState()
  31. {
  32.     var ready=req.readyState;
  33.     var data="sad";
  34.     if (ready==4)
  35.     {
  36.         if(req.status==200)
  37.         {
  38.             data=req.responseText;
  39.         }
  40.     }
  41.     else
  42.     {
  43.         data="loading...["+ready+"]";
  44.     }
  45.     toConsole(data);
  46. }
  47. function toConsole(data)
  48. {
  49.     if (console!=null)
  50.     {
  51.  
  52.         var newline=document.createElement("div");
  53.         console.appendChild(newline);
  54.         var txt=document.createTextNode(data);
  55.         newline.appendChild(txt);
  56.  
  57.     }
  58. }
  59. function abc()
  60. {
  61.     console=document.getElementById("simple_div");
  62.     sendRequest("http://localhost:8080/bit/simple.jsp","GET");
  63. }
JSP code
Expand|Select|Wrap|Line Numbers
  1. <%
  2. String abcd=request.getParameter("name");
  3. response.setContentType("text/html");
  4. response.setHeader("Cache-Control","no-cache");
  5. response.getWriter().write(abcd);
  6. %>
Thanks in advance
Mar 19 '08 #6
gits
5,390 Recognized Expert Moderator Expert
try to change the following things to this:

Expand|Select|Wrap|Line Numbers
  1. function sendRequest(url, HttpMethod) {    
  2.     if (!HttpMethod) {
  3.         HttpMethod="GET";
  4.     }
  5.  
  6.     var req = initXMLHTTPRequest();
  7.  
  8.     if (req) {
  9.         req.open(HttpMethod, url, true);
  10.         req.onreadystatechange = onReadyState;
  11.         req.send(null);
  12.     }
  13. }
  14.  
  15. function onReadyState(req) {
  16.     var ready = req.readyState;
  17.     var data = "sad";
  18.  
  19.     if (ready==4) {
  20.         if(req.status==200) {
  21.             data=req.responseText;
  22.         }
  23.     } else {
  24.         data="loading...["+ready+"]";
  25.     }
  26.  
  27.     toConsole(data);
  28. }
  29.  
kind regards
Mar 19 '08 #7
jomshri
7 New Member
HI Gits
Thanks for reply
But that code also didn't run ,even it doesn't display anything I mean neither null nor correct value.Please reply me as soon as possible.

thanks
Mar 24 '08 #8
gits
5,390 Recognized Expert Moderator Expert
HI Gits
Thanks for reply
But that code also didn't run ,even it doesn't display anything I mean neither null nor correct value.Please reply me as soon as possible.

thanks
hi ...

try this:

Expand|Select|Wrap|Line Numbers
  1. req.onreadystatechange = function(res) {
  2.      return onReadyState(res);
  3. }(req);
kind regards
Mar 24 '08 #9
jomshri
7 New Member
Thanks for reply
But i didn't get what is that (res) i.e. res
Is that is used for response or for ajax variable
Please reply as soon as possible
thanks
Mar 25 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
45715
by: Luis | last post by:
Is there an easier way to check if any of the fields returned in a select statement have null values? After running this command: set rs = conn.execute("select A,B,C,D,E,F,G,H,I,J from SomeTable where...") I could check each field this way:
3
1712
by: Shawn | last post by:
Hey there i'm trying to post a section of XML code to an XMLSocket Server via ASP I can successfully connect to the server, but it won't disconnect because the string needs a null character inserted at the end in order for the socket server to terminate the connection. how would i do this? i've tried chr(32), chr(0).. anyother ideas? newdoc="<USER> +19024894124</USER><MESSAGE>test </MESSAGE><USERID>+19024894124 </USERID>"
3
4689
by: Danny Tuppeny | last post by:
Hi all, I'm trying to send a null character as a string delimiter through a TcpClient (code below). It's to connect to this poker bot room: http://games.cs.ualberta.ca/webgames/poker/bots.html My code is as below, but I never get a response. I'm assuming my transmission is ending at the null character (the debug statement certainly only outputs up until the null character). Any ideas?
4
9526
by: kyl | last post by:
A Java Axis consumed by .Net C# client, it built and executed the WS method from the WSDL gotten from OK, the response object is NULL. Is there any more thing more should be done on Java server?
9
3220
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. What it does is to call a webservice with two parameters, one being a integer, the other one being a "String" which contains XML (not the best practice, however that is the target interface and we cannot change that).
7
1782
by: news | last post by:
..Net 2.0 Hi, I'm getting a nullreferenceexception when calling a function from a worker thread: private void CallbackProc(string response, Exception ex) { if (this.InvokeRequired) { this.Invoke(new MyCallback(CallbackProc), new object {
2
14677
by: Uldis Bojars | last post by:
Hi All, I have encountered problems with JS RegExp.exec() and can't find what is the problem. Could you help me? formRequest is a function that extracts some information from XMLHTTPRequest response. A very strange effect (and I can't find where I've done something wrong) is that regexp matches in this function fail on every second call.
0
2282
by: alister7 | last post by:
hi every1 im trying to download a music file from the database SQLserver.which i upload in the database.. The Code below works fine in wen i create a new project of an ASP.Net web application..m using VS 2008 but it gives me an error wen i run the same code in WPF broser APplication(xbap).. it throws an error saying Null reference encountered. the line of error is HTTPcontext context=HTTPcontext.Current; it goes in the else part of the...
2
3105
by: crabsdf | last post by:
My project is a single method class which takes a xml object and, using Apache FOP, transforms it into a PDF which is returned as an output stream. Here is full code package transactionStatement; import javax.xml.transform.TransformerFactory; import javax.servlet.*; import org.jdom.*; import java.io.ByteArrayOutputStream; import java.io.File;
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10327
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10151
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.