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
> 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
In JavaScript, you can do:
var oImg = new Image;
oImg.src = "http://wherever/yourLogUtility?param1=x¶m2=y";
However, the above http request won't get issued when users
have image display turned off.
Boniface
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
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¶m2=y" +
"¶m3=" + (new Date()).getTime();
Boniface
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¶m2=y&makeUnique=" + (new
Date()).valueOf(); />
I've wrapped it in <url /> tags to keep it on a single line.
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
> >
> > 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¶m2=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).
> 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!