You shouldn't have to hit the DOM at all:
function fireAndForget( url ) {
(new Image).src = url;
}
Jed Schmidt
On Apr 7, 8:54 am, Chuck Harmston <[email protected]> wrote:
> I really like Weepy's idea, very clever. Rough, untested idea of how it
> might work:
> jQuery.fn.fireForget = function( url ) {
> $( 'body' ).append( '<img src="' + url + '" alt="" class="fireForget" />' );
> $( '.fireForget' ).css({
> 'position' : 'absolute',
> 'visibility' : 'hidden'
>
> });
> };
>
> Then you just run:
>
> $.fireForget('http://127.0.0.1/log.php?errortype=500');
>
> Of course substituting log.php with a server-side script of your choice.
> After running your code in the server-side script, you'd want to pass a 302
> status code to redirect the script to a blank.gif or something. Make sure
> it's a 302 (REDIRECT) and not a 301 (PERMANENT REDIRECT), or browsers will
> start caching the image and not run the code.
>
> Chuck Harmstonhttp://chuckharmston.com
>
> On Tue, Apr 7, 2009 at 10:14 AM, DBJDBJ <[email protected]> wrote:
>
> > I am not clear are you looking for a design or implementation pattern/
> > mechanism?
>
> > It is not very difficult to send things to the server:
> > (http://developer.yahoo.com/common/json.html)
>
> > <html>
> > <head>
> > <title>How Many Pictures Of Madonna Do We Have?</title>
> > </head>
> > </body>
> > <script type="text/javascript">
> > function ws_results(obj) {
> > alert(obj.ResultSet.totalResultsAvailable);
> > }
> > </script>
> > <script type="text/javascript" src="http://search.yahooapis.com/
> > ImageSearchService/V1/imageSearch?
> > appid=YahooDemo&query=Madonna&output=json&callback=ws_results"></
> > script>
> > <body></body>
> > </html>
>
> > In essence any dom element that has an src attribute can be used.
> > Example above is JSONP quasy-protocol, so it should do cross-domain
> > calls too ... Although, I am sure this example will have to be tested
> > with the full matrix of all browsers on all platforms. As I am sure
> > that security anywhere in that matrix will do its best to stop you
> > >:o)
>
> > jQuery and logging errors to the server?
> > Maybe something like this:
>
> > $(window).error(function(msg, url, line) {
> > $.ajax( {
> > url: "http://mikegale.com/errlog" ,
> > type: "POST",
> > global: false,
> > cache: false,
> > data: '{ msg : \"" + msg +
> > "\", url: \"" + url + "\", line: \"" +
> > line + "\"" }'
> > } ) ;
> > });
>
> > Or I have missed the issue completely ?
>
> > --DBJ
>
> > On Apr 6, 11:31 pm, "Mike Gale" <[email protected]> wrote:
> > > Thanks Jonah.
>
> > > I use something like that elsewhere (an HTTP handler that logs "get
> > strings" sent to it and returns an image) but I can't see a
> > > clean way of making it fit into this job.
>
> > > A little more detail.
>
> > > My service has a bunch of methods that accept posted data and return
> > various things like serialized content of drop downs and xhtml
> > > formatted reports.
>
> > > It's a nice clean architecture (compiled code on the server, jQuery on
> > the browser).
>
> > > I would like to have the ability to log exceptions on the browser, if
> > they occur in selected places (within try catch structures).
> > > This would bring browser issues into line with server side code, where
> > I'm logging exceptions. I'd really like a uniform mechanism,
> > > in line with my remote method calls via jQuery. (But without any
> > unneeded complexity.)
>
> > > I'm abstracted away from the marshalling plumbing with jQuery, which I
> > like.
>
> > > I could create an alternate XMLHTTP handler (in JavaScript) which throws
> > the callback/response away, but I'd prefer not to do that.
>
> > > Regards,
>
> > > Mike Gale
>
> > > CAUTION - This message may contain privileged and confidential
> > information intended only for the use of the addressee/s.
>
> > > If you are not the intended recipient of this message you are hereby
> > notified that any use, dissemination, distribution or
> > > reproduction of this message is prohibited without prior written consent.
> > Any views expressed in this message may not reflect the
> > > views of Decision Engineering.
>
> > > -----Original Message-----
> > > From: [email protected] [mailto:[email protected]]
> > On Behalf Of weepy
> > > Sent: 2009/04/7 6:26
> > > To: jQuery Development
> > > Subject: [jquery-dev] Re: Fire and Forget requests using jQuery
>
> > > you could create an image element with a src pointing towards your
> > > destination url
>
> > > On 6 Apr, 03:55, Mike Gale <[email protected]> wrote:
> > > > I have some non-critical logging messages I want to send from
> > > > browsers.
>
> > > > I don't want the browser to wait for a response, or use up an
> > > > available xhr channel.
>
> > > > The rest of the app is jQuery talking to a webservice on the server.
>
> > > > XMLHTTP is, as far as I know, a protocol that assumes you want a
> > > > response and has no mechanism for fire and forget. I could set up
> > > > JavaScript code that aborted the xhr, maybe on status changed, but
> > > > that seems kludgy.
>
> > > > As far as I know, there is no native jQuery way to send a "fire and
> > > > forget" message.
>
> > > > What ways are suggested to achieve this, preferably using jQuery?
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---