Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HTTP request in Javascript

9 views
Skip to first unread message

Mazen Mokhtar

unread,
Jul 19, 2002, 3:03:13 PM7/19/02
to
Hello,

Is there a way to programmatically make an HTTP request in
Javascript, in such as way that the results are either ignored or
captured in a String?

I have a URL which places some information in a log, but it doesn't
need to return anything and certainly shouldn't be considered a link.
In order to achieve this effect, I am using frames. In psudo code:

do_some_processing
log_form_field.value = "Log string"
log_form.submit( ) <-- target is frame_2
do_some_more_processing

I would rather achieve the same effect programmatically, for
example:

do_some_processing
web_page = new Page(log_url + "?val=LogString")
web_page.open( );
foreach(line in web_page) {
do_something_with_the_line
}
web_page.close( );

This way, I can remove the for loop and avoid the browser delay of
waiting for an unnecessary response from the log_url.


Thank you all in advance,


Mazen Mokhtar

Grant Wagner

unread,
Jul 19, 2002, 4:10:53 PM7/19/02
to
Mazen Mokhtar wrote:

> Hello,
>
> Is there a way to programmatically make an HTTP request in
> Javascript, in such as way that the results are either ignored or
> captured in a String?

<url: http://jibbering.com/2002/4/httprequest.html />

--
| Grant Wagner <gwa...@agricoreunited.com>

* Client-side Javascript and Netscape DOM Reference available at:
* http://developer.netscape.com/docs/manuals/javascript.html
* Internet Explorer DOM Reference available at:
* http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtmlrefs.asp

* Tips for upgrading JavaScript for Netscape 6/Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html


Boniface Lau

unread,
Jul 19, 2002, 8:22:04 PM7/19/02
to
Mazen Mokhtar wrote:
>
> Hello,
>
> Is there a way to programmatically make an HTTP request in
> Javascript, in such as way that the results are either ignored or
> captured in a String?

In JavaScript, you can do:

var oImg = new Image;
oImg.src = "http://wherever/yourLogUtility?param1=x&param2=y";

However, the above http request won't get issued when users
have image display turned off.


Boniface

Mazen Mokhtar

unread,
Jul 21, 2002, 3:13:30 PM7/21/02
to

Thank you very much, to you and to Grant Wagner for answering my
question. In experimenting with this solution, I found that you
sometimes need an additional unique parameter to bypass browser
caching if you want to ensure that similar calls to the log go to the
server every time.


Mazen Mokhtar

Boniface Lau

unread,
Jul 21, 2002, 7:36:52 PM7/21/02
to

Yes. You can ensure uniqueness by specifying the current time in
milliseconds. Thus, every time you want to issue an http request, you
do:

oImg.src = "http://wherever/yourLogUtility?param1=x&param2=y" +
"&param3=" + (new Date()).getTime();

Boniface

Randy Harmelink

unread,
Jul 23, 2002, 10:35:21 PM7/23/02
to
Boniface Lau <Bonifa...@compuserve.com> wrote:he server every time.

>
> Yes. You can ensure uniqueness by specifying the current time in
> milliseconds. Thus, every time you want to issue an http request, you
> do:
>
> oImg.src = "http://wherever/yourLogUtility?param1=x&param2=y" +
> "&param3=" + (new Date()).getTime();
>

Any suggestion on how to make the URL unique for a CGI call? Such as:

http://thisspot/thisdirectory/xxxx.cgi?parm

I've tried several variations on the "parm" field, with all coming
back as invalid if I make any change.

Grant Wagner

unread,
Jul 24, 2002, 9:55:20 AM7/24/02
to
Randy Harmelink wrote:

He provided code on how to make the URL unique above:

<url: oImg.src =
"http://wherever/yourLogUtility?param1=x&param2=y&makeUnique=" + (new
Date()).valueOf(); />

I've wrapped it in <url /> tags to keep it on a single line.

Boniface Lau

unread,
Jul 24, 2002, 6:23:43 PM7/24/02
to
Randy Harmelink wrote:
>
> Boniface Lau <Bonifa...@compuserve.com> wrote:
> >
> > Yes. You can ensure uniqueness by specifying the current time in
> > milliseconds. Thus, every time you want to issue an http request,
> > you do:
> >
> > oImg.src = "http://wherever/yourLogUtility?param1=x&param2=y" +
> > "&param3=" + (new Date()).getTime();
> >
>
> Any suggestion on how to make the URL unique for a CGI call? Such
> as:
>
> http://thisspot/thisdirectory/xxxx.cgi?parm
>
> I've tried several variations on the "parm" field, with all coming
> back as invalid if I make any change.

You can add a search string to the tail end of the url. Thus,

sUrl = 'http://thisspot/thisdirectory/xxxx.cgi';

becomes

sUrl = 'http://thisspot/thisdirectory/xxxx.cgi' + '#' +
(new Date()).getTime();

If your url includes parameters, make sure that they are all placed
before the "#" character.


Boniface

Randy Harmelink

unread,
Jul 24, 2002, 10:05:15 PM7/24/02
to
Grant Wagner <gwa...@agricoreunited.com> wrote:

> >
> > Any suggestion on how to make the URL unique for a CGI call? Such as:
> >
> > http://thisspot/thisdirectory/xxxx.cgi?parm
> >
> > I've tried several variations on the "parm" field, with all coming
> > back as invalid if I make any change.
>
> He provided code on how to make the URL unique above:
>
> <url: oImg.src =
> "http://wherever/yourLogUtility?param1=x&param2=y&makeUnique=" + (new
> Date()).valueOf(); />
>
> I've wrapped it in <url /> tags to keep it on a single line.

I have it working for normal URLs. That's why I specifically asked
about the CGI call. One CGI call I'm trying to use apparently doesn't
parse the "parm" into individual variable pairs. I think it is
expecting a single string. So appending anything to it gives it an
unrecognizable parameter and the CGI call returns an error -- at least
anything I tried appending (before and/or after).

Randy Harmelink

unread,
Jul 25, 2002, 11:26:16 PM7/25/02
to
Boniface Lau <Bonifa...@compuserve.com> wrote:

> You can add a search string to the tail end of the url. Thus,
>
> sUrl = 'http://thisspot/thisdirectory/xxxx.cgi';
>
> becomes
>
> sUrl = 'http://thisspot/thisdirectory/xxxx.cgi' + '#' +
> (new Date()).getTime();
>
> If your url includes parameters, make sure that they are all placed
> before the "#" character.
>
>
> Boniface

That did the trick. Thanks so much!

0 new messages