473,385 Members | 1,927 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,385 software developers and data experts.

"AJAX" - sending but don't need response?

I have a situation where I want to send data, but I have no need for a
response. It seems to me that XMLHTTPRequest is the best way to send the
data, but I don't need any response back from the server.

Basically, I'm writing js errors to an error log on the server side -
and there is no need to inform the user that the error has been logged.

The problem is that I don't want to sit with the request open & waiting
for a response, when I have no need for the response. I suppose I could
have the server respond with just "OK" or something like that, but it's
really not relevant

I was thinking of just aborting the request on readystate=1 (at that
point, the server-side script should have executed already, right?), but
I was wondering if there were any other methods to JUST send..

Thanx
Mar 6 '06 #1
20 4071
VK

Tony wrote:
I have a situation where I want to send data, but I have no need for a
response. It seems to me that XMLHTTPRequest is the best way to send the
data, but I don't need any response back from the server.


Not a script question. See HTTP specs, 204 / No Content response

Mar 6 '06 #2
Tony said the following on 3/6/2006 3:33 PM:
I have a situation where I want to send data, but I have no need for a
response. It seems to me that XMLHTTPRequest is the best way to send the
data, but I don't need any response back from the server.


No, XMPHTTPRequest is not the best way to send the data. Especially
since you don't need the response.

myVar = new Image();
myVar.src = "pathToServerSideScript.ext?" + errorMessage;

Then the server side script executes and nothing is done with the response.

This is so widely asked that its in the FAQ:

<URL: http://jibbering.com/faq/#FAQ4_34 >

"How do I execute a server side script?"

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 6 '06 #3
Randy Webb wrote:
Tony said the following on 3/6/2006 3:33 PM:
I have a situation where I want to send data, but I have no need for a
response. It seems to me that XMLHTTPRequest is the best way to send
the data, but I don't need any response back from the server.


No, XMPHTTPRequest is not the best way to send the data. Especially
since you don't need the response.

myVar = new Image();
myVar.src = "pathToServerSideScript.ext?" + errorMessage;


This old trick always work, but it's just a trick, I think the XHR is
the right way of doing it. Besides the fact that the query string has a
size limit too, so this trick isn't the best way to send data either.

If you don't need to send a good amount of data or if you need
compatibility with old browsers, ok... Use the query string.

Otherwise I'm all for XHR \o/, since for me it's clearly the right way,
if the response doesn't matter for you, don't even generate it! Since
you will just need to check headers (there's a method to just fetch the
headers on this XHR object, but I think it's not present on IE, search a
little hehe).
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Mar 6 '06 #4
Randy Webb wrote:
Tony said the following on 3/6/2006 3:33 PM:
I have a situation where I want to send data, but I have no need for a
response. It seems to me that XMLHTTPRequest is the best way to send
the data, but I don't need any response back from the server.

No, XMPHTTPRequest is not the best way to send the data. Especially
since you don't need the response.

myVar = new Image();
myVar.src = "pathToServerSideScript.ext?" + errorMessage;

Then the server side script executes and nothing is done with the response.

This is so widely asked that its in the FAQ:

<URL: http://jibbering.com/faq/#FAQ4_34 >

"How do I execute a server side script?"


Ah - I DID search (although I didn't think to look specifically at the
FAQ for this group) - but didn't come up with much. Probably wasn't
phrasing it in the best way, I'd say.

Thanx
Mar 6 '06 #5
VK wrote:
Tony wrote:
I have a situation where I want to send data, but I have no need for a
response. It seems to me that XMLHTTPRequest is the best way to send the
data, but I don't need any response back from the server.

Not a script question. See HTTP specs, 204 / No Content response


Not quite what I'm looking for - in that case, there is STILL a
response. Unless I'm badly misunderstanding something, that would
generate the full set of readyState changes from 1-4, right?

What I'd like is to not even have to get a response back AT ALL, not
even a 204, no headers, nothing...

Mar 6 '06 #6
VK

Tony wrote:
VK wrote:
Tony wrote:
I have a situation where I want to send data, but I have no need for a
response. It seems to me that XMLHTTPRequest is the best way to send the
data, but I don't need any response back from the server.

Not a script question. See HTTP specs, 204 / No Content response


Not quite what I'm looking for - in that case, there is STILL a
response. Unless I'm badly misunderstanding something, that would
generate the full set of readyState changes from 1-4, right?

What I'd like is to not even have to get a response back AT ALL, not
even a 204, no headers, nothing...


Right - and for this you don't need any Ajax nor even script. Simply
submit your form using GET or POST. You server has to send back 204 No
Content. For user it will look like nothing changed at all - browser
will stay on the same page, no refresh.

Mar 6 '06 #7
Tony wrote:
Randy Webb wrote:
Ah - I DID search (although I didn't think to look specifically at the
FAQ for this group) - but didn't come up with much. Probably wasn't
phrasing it in the best way, I'd say.


Man, why are you so crazy to avoid responses??? You're looking like
those people that say:

PLEASE, HELP ME!!! I want to do "X", but not this way, not using "Y" and
don't even think about "Z"!

If you don't need answer, just don't output anything, the responses will
always be there, unless the browser cuts the connection \o/

Even this trick will try to read some content... It's expecting a binary
representation of an image, but it will receive an strange header and
won't parse =)
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Mar 6 '06 #8
On 06/03/2006 22:39, Jonas Raoni wrote:

[snip]
Man, why are you so crazy to avoid responses???
Indeed. HTTP is a request/response transport protocol. Any request will
illicit a response unless something badly wrong happens.

[snip]
Even this trick [modifying an image URL] will try to read some
content... It's expecting a binary representation of an image, but it
will receive an strange header and won't parse =)


Not true. The image request will still be a HTTP request, so the browser
will be expecting headers. It would only be parsing strange information
if the server returned content (with a 200 OK response, for example) and
that data wasn't image data in the format indicated by the Content-Type
response header.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Mar 6 '06 #9
Michael Winter wrote:
On 06/03/2006 22:39, Jonas Raoni wrote:
Not true. The image request will still be a HTTP request, so the browser
will be expecting headers. It would only be parsing strange information
if the server returned content (with a 200 OK response, for example) and
that data wasn't image data in the format indicated by the Content-Type
response header.


Yes, that's right, besides these things you said, it would be smart to
check the image header. But this isn't a rule, it depends of the browser =]

If the browser has a bug on the image parser, I could send a recognized
image content-type, send the right image header and then output a
content to generate a crazy loop on it, for sure I would need to know
how it works.
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Mar 6 '06 #10
VK wrote:
Tony wrote:
Not quite what I'm looking for - in that case, there is STILL a
response. Unless I'm badly misunderstanding something, that would
generate the full set of readyState changes from 1-4, right?

What I'd like is to not even have to get a response back AT ALL, not
even a 204, no headers, nothing...

Right - and for this you don't need any Ajax nor even script. Simply
submit your form using GET or POST. You server has to send back 204 No
Content. For user it will look like nothing changed at all - browser
will stay on the same page, no refresh.


OK - that helps some. I actually think that it won't work in the
specific circumstance I have, but I will certainly check it out. Thanx

Mar 6 '06 #11
Jonas Raoni wrote:

Man, why are you so crazy to avoid responses??? You're looking like
those people that say:

PLEASE, HELP ME!!! I want to do "X", but not this way, not using "Y" and
don't even think about "Z"!
I guess I am, at that :) Well, sometimes, that's just the way the
problem gets posed to me, you know?
If you don't need answer, just don't output anything, the responses will
always be there, unless the browser cuts the connection \o/
Which is my main concern - I don't want to open a request and have it
sit there open indefinitely. Also, I have a need to save as much
bandwidth as possible for this (which no response would work for). I
suppose I could abort it on a short timeout or do something like that -
I'm working through the possibilities...

Mainly, I'm just looking for some input: A lot of times, even if I don't
get a direct answer from posting here, the feedback gets me pointed in a
better direction...
Even this trick will try to read some content... It's expecting a binary
representation of an image, but it will receive an strange header and
won't parse =)

Mar 6 '06 #12
Tony wrote:
VK wrote:
Tony wrote:
I have a situation where I want to send data, but I have no need for a
response. It seems to me that XMLHTTPRequest is the best way to send the
data, but I don't need any response back from the server.
Not a script question. See HTTP specs, 204 / No Content response


Not quite what I'm looking for - in that case, there is STILL a
response.


There is _always_ a response, unless the HTTP server is down. However,
status code 204 indicates that the response body can be disregarded by
the client.
Unless I'm badly misunderstanding something, that would
generate the full set of readyState changes from 1-4, right?
Most certainly. You could just test it.
What I'd like is to not even have to get a response back AT ALL, not
even a 204, no headers, nothing...


Do not use HTTP then. Ref. RFC1945/2616: HTTP is a request-response chain.
PointedEars
Mar 7 '06 #13
Jonas Raoni said the following on 3/6/2006 5:19 PM:
Randy Webb wrote:
Tony said the following on 3/6/2006 3:33 PM:
I have a situation where I want to send data, but I have no need for
a response. It seems to me that XMLHTTPRequest is the best way to
send the data, but I don't need any response back from the server.
No, XMPHTTPRequest is not the best way to send the data. Especially
since you don't need the response.

myVar = new Image();
myVar.src = "pathToServerSideScript.ext?" + errorMessage;


This old trick always work,


Remember that! :)
but it's just a trick, I think the XHR is the right way of doing it.
Then you think wrong :)
Besides the fact that the query string has a size limit too, so this
trick isn't the best way to send data either.
Yes, the querystring has a size limit. But using the img.src "trick" as
you call it is more reliable and can be used and get around the URL size
limit. Create 10 images and now you have 10 times the data going to the
server - as long as the server knows how to accept/handle it.

If you don't need to send a good amount of data or if you need
compatibility with old browsers, ok... Use the query string.
Or if you just want a simple way where you don't need the results (which
is precisely what the OP wanted).
Otherwise I'm all for XHR \o/, since for me it's clearly the right way,
if the response doesn't matter for you, don't even generate it! Since
you will just need to check headers (there's a method to just fetch the
headers on this XHR object, but I think it's not present on IE, search a
little hehe).


To check the headers, guess what? The response has to be generated or
there is no header to check. And that is not what the OP wanted - no
response.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 7 '06 #14
Jonas Raoni said the following on 3/6/2006 5:39 PM:
Tony wrote:
Randy Webb wrote:
Ah - I DID search (although I didn't think to look specifically at the
FAQ for this group) - but didn't come up with much. Probably wasn't
phrasing it in the best way, I'd say.


Man, why are you so crazy to avoid responses??? You're looking like
those people that say:

PLEASE, HELP ME!!! I want to do "X", but not this way, not using "Y" and
don't even think about "Z"!


Where did he say "don't even think about Z"? He didn't. He asked a
question and got a better reply. One that is even covered in this groups
FAQ.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 7 '06 #15
Randy Webb wrote:
Jonas Raoni said the following on 3/6/2006 5:19 PM:
Randy Webb wrote:
Tony said the following on 3/6/2006 3:33 PM: This old trick always work,


Remember that! :)
but it's just a trick, I think the XHR is the right way of doing it.


Then you think wrong :)


It just depends of your point of view, the right solution is the
solution that fills the requirements.
Besides the fact that the query string has a size limit too, so this
trick isn't the best way to send data either.


Yes, the querystring has a size limit. But using the img.src "trick" as
you call it is more reliable and can be used and get around the URL size
limit. Create 10 images and now you have 10 times the data going to the
server - as long as the server knows how to accept/handle it.


This sounds bizarre to me, a workaround over another workaround. If
there's a way to avoid making such strange things, why not use it? :]

You'll end up having something like this:

(new Image).src = "add?id=1&piece=0&data=abc";
(new Image).src = "add?id=1&piece=1&data=def";
:

If you don't need to send a good amount of data or if you need
compatibility with old browsers, ok... Use the query string.


Or if you just want a simple way where you don't need the results (which
is precisely what the OP wanted).


For me it will always look like what we call here "gambiarra". Yes! It's
very simple, but it's a subversion of the feature, the Image is supposed
to load images, not make fancy requests.
And that is not what the OP wanted - no response.


He's lost.

"Basically, I'm writing js errors to an error log on the server side -
and there is no need to inform the user that the error has been logged."

He doesn't need to inform the user, but it would be nice to be sure that
the error was logged right ;]
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Mar 7 '06 #16
Randy Webb wrote:
Jonas Raoni said the following on 3/6/2006 5:39 PM:
Man, why are you so crazy to avoid responses??? You're looking like
those people that say:

PLEASE, HELP ME!!! I want to do "X", but not this way, not using "Y"
and don't even think about "Z"!


Where did he say "don't even think about Z"? He didn't. He asked a
question and got a better reply. One that is even covered in this groups
FAQ.


"You're *looking like* those people that say [...]"
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Mar 7 '06 #17
Jonas Raoni said the following on 3/7/2006 2:18 AM:
Randy Webb wrote:
Jonas Raoni said the following on 3/6/2006 5:19 PM:
Randy Webb wrote:

Tony said the following on 3/6/2006 3:33 PM:
This old trick always work,


Remember that! :)
but it's just a trick, I think the XHR is the right way of doing it.


Then you think wrong :)


It just depends of your point of view, the right solution is the
solution that fills the requirements.


Very true but the right solution is also a solution that doesn't
overfill the requirements. A sledgehammer will drive a nail in your wall
to hang a picture but that isn't the best solution :)
Besides the fact that the query string has a size limit too, so this
trick isn't the best way to send data either.


Yes, the querystring has a size limit. But using the img.src "trick"
as you call it is more reliable and can be used and get around the URL
size limit. Create 10 images and now you have 10 times the data going
to the server - as long as the server knows how to accept/handle it.


This sounds bizarre to me, a workaround over another workaround. If
there's a way to avoid making such strange things, why not use it? :]

You'll end up having something like this:

(new Image).src = "add?id=1&piece=0&data=abc";
(new Image).src = "add?id=1&piece=1&data=def";
:


I didn't say it wouldn't be messy :) And yes, trying to get around the
URL limit would be messy with an Image src.

If the URL length is a problem, then you can submit a hidden IFrame to
itself. The response gets handled by the browser but the user still
never sees it.

But, I have never seen an error message that exceeded 1000 characters,
not even a custom error message. But if the custom error message is that
large, then it should be constructed on the server anyway.

If you don't need to send a good amount of data or if you need
compatibility with old browsers, ok... Use the query string.


Or if you just want a simple way where you don't need the results
(which is precisely what the OP wanted).


For me it will always look like what we call here "gambiarra". Yes! It's
very simple, but it's a subversion of the feature, the Image is supposed
to load images, not make fancy requests.


It's not about subversion of a feature as much as it is supported
features though. When the XMLHTTPRequest gains wider support, then yes
it would be the best way. But right now, it just doesn't have wide
enough support whereas the image.src route does.
And that is not what the OP wanted - no response.


He's lost.


And you want to tell him to use an XMLHTTPRequest object over setting
the src of a dummy Image()? Think about that one :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 7 '06 #18
Randy Webb wrote:
It just depends of your point of view, the right solution is the
solution that fills the requirements.
Very true but the right solution is also a solution that doesn't
overfill the requirements. A sledgehammer will drive a nail in your wall
to hang a picture but that isn't the best solution :)


I agree. But I do like strong solutions, whenever I make little fixes, I
always find myself making new little fixes, because they got outdated
haha ;]
If the URL length is a problem, then you can submit a hidden IFrame to
itself. The response gets handled by the browser but the user still
never sees it.
As I don't work as web developer, I stopped writing these things when I
saw they were quite strange solutions. Now I just aim at updated
versions of ie, ff and opera, the rest is rest (I would test on safari,
but I don't have a mac haha), I try to do things in a not blocking way,
so if the user insists about using bad gasoline on his Ferrari, there's
nothing I can do :]
But, I have never seen an error message that exceeded 1000 characters,
not even a custom error message. But if the custom error message is that
large, then it should be constructed on the server anyway.
I doubt he will exceed this limit and I'm not sure if it's just 1000
chars, I tested once and I received a lot more than that ;]
It's not about subversion of a feature as much as it is supported
features though. When the XMLHTTPRequest gains wider support, then yes
it would be the best way. But right now, it just doesn't have wide
enough support whereas the image.src route does.
As I said, old browsers doesn't matter for me =]
And you want to tell him to use an XMLHTTPRequest object over setting
the src of a dummy Image()? Think about that one :)


No, I just said what I would do, he has the right to decide what he will
use... Even this XHR isn't a nice way since it's not a standard, but it
doesn't matter :]
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Mar 7 '06 #19
"Tony" <to****@dslextreme.WHATISTHIS.com> wrote in message
news:12*************@corp.supernews.com...
I have a situation where I want to send data, but I have no need for a
response. It seems to me that XMLHTTPRequest is the best way to send the
data, but I don't need any response back from the server.

Basically, I'm writing js errors to an error log on the server side - and
there is no need to inform the user that the error has been logged.

The problem is that I don't want to sit with the request open & waiting
for a response, when I have no need for the response. I suppose I could
have the server respond with just "OK" or something like that, but it's
really not relevant

I was thinking of just aborting the request on readystate=1 (at that
point, the server-side script should have executed already, right?), but I
was wondering if there were any other methods to JUST send..

Thanx


I've coded some AJAX where I didn't know a response. Since I didn't
need it to do anything when it was finished, I just didn't declared an
onreadystatechange function. So basically, all you're doing is sending
the data and that's it.
Mar 20 '06 #20
VK

Tony wrote:
Which is my main concern - I don't want to open a request and have it
sit there open indefinitely. Also, I have a need to save as much
bandwidth as possible for this (which no response would work for). I
suppose I could abort it on a short timeout or do something like that -
I'm working through the possibilities...


You are just thinking too linear: a common error reproduced in many
server-side scripts ;-)
1) server got request
2) server is working with request
3) server sent response back

If the stage 2 takes too long, people starting to bother with problems
similar to yours. A hint: stages 2 and 3 are _interchangeable_

1) server got request
2) server sent back 204 No Content to close connection
3) server is working with request

Your traffic and connection time by definition cannot be lesser than
necessary to send data from client to server, so this is a maximum
effective schema one can have. I guess you can go with 1 (one) extra
TCP/IP package sent from the server ;-)

Mar 21 '06 #21

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

Similar topics

8
by: Don Miller | last post by:
I've been extensively modifying a web application (ASP, COM+) to take advantage of the XMLHTTP object for asynchronous requests (e.g. Ajax) on my dev machine (Win2KPro). I test the application from...
3
by: Tony | last post by:
I've done a fair bit of searching on this, but I want to be certain about what I've found - so here goes with a long example and three questions: For clarity, let me give an example (a number of...
6
by: blueapricot416 | last post by:
I have some javascript in a standard HTML page that uses the ubiquitous "XMLHttpRequest" to send data to a remote ASP page. If that page "answers back" by sending a string using a simple...
4
by: keyofdminor | last post by:
Folks, Short version: Has anyone tried a synchronous call ("SJAX") to a server with the Prototype library? I'm curious if there is a bug in the library (possible) or if I am making mistake...
1
by: mark4asp | last post by:
Which should I use: 1. "ASP.NET AJAX-Enabled Web Site" or 2. "AJAX Control Toolkit Web Site"? In the first, controls from the control toolkit start as: <cc1:SomeControl></cc1> In the 2nd,...
5
by: Sommer.pde | last post by:
It took me some time to find out when and why this happens. When the window of Internet Explorer is closed with an AJAX call still pending, something funny happens. Do it twice, and you will have...
2
hsriat
by: hsriat | last post by:
I have a page working on Ajax. The problem is, after doing many changes using Ajax (like uploading, changing name, adding to favorites etc), the status bar starts behaving unexpectedly. Even when...
11
by: Jonathan Wood | last post by:
Can anyone point me to any good resources on adding AJAX to a page once the page has already been created? I know VS2008 has options to add AJAX pages, but I didn't select those options when the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.