[jQuery] Re: closure inside ajax method
The order of elements in a simple array like this is guaranteed. Looping over an object with a for in loop, the order is not guaranteed, though by convention most browsers honor the order in which the elements were added. jQuery would have to go out of its way to return the elements from your array in a different order. So, yes, you can count on the order being correct. To answer your original question, the "jQuery way" to do this would be to use $.each(). If you wanted to achieve the closure in pure JavaScript, you could do the following: var i, len, myArray = ['one', 'two'], innerFunc; innerFunc = function (i) { $.ajax({ url : 'http://localhost/', complete : function () { alert(i); } }); } for (i = 0, len = myArray.length; i < len; ++i) { innerFunc(i); } On Jan 28, 5:52 am, bob wrote: > Thanks, > Can't closure be achieved with for loop? > for(var i=0; i > My concern is: > Does > $.each > process the "scripts" array items in the exact order they are in the > array?
[jQuery] Re: $.ajax beforeSend Accept-Encoding behavior
OK, I now see the console message where jQuery refuses to set the unsafe header, so it looks like this behavior is expected. I am having trouble finding a good explanation of what is unsafe about it though. Is it that this header is unsafe when used in combination with some other header value (say, a particular MIME type or charset)? In other words, is there no way to change this? On Jan 26, 2:41 pm, Andrew Hedges wrote: > I'm trying to make an Ajax request, specifically requesting a non- > gzipped response. Here's how I am going about it: > > $.ajax({ > url : 'http://my.valid.url/', > method : 'get', > beforeSend : function (xhr) { > xhr.setRequestHeader('Accept-Encoding', 'identity'); > xhr.setRequestHeader('X-Test', 'foo'); > } > > }); > > Watching the action with LiveHTTPHeaders in Firefox 3, I can see that > "X-Test: foo" gets set correctly, but I'm still seeing "Accept- > Encoding: gzip,deflate". Is this expected behavior? If so, is there a > reason why I can't change the Accept-Encoding value? > > Thanks, > -Andrew
[jQuery] $.ajax beforeSend Accept-Encoding behavior
I'm trying to make an Ajax request, specifically requesting a non- gzipped response. Here's how I am going about it: $.ajax({ url : 'http://my.valid.url/', method : 'get', beforeSend : function (xhr) { xhr.setRequestHeader('Accept-Encoding', 'identity'); xhr.setRequestHeader('X-Test', 'foo'); } }); Watching the action with LiveHTTPHeaders in Firefox 3, I can see that "X-Test: foo" gets set correctly, but I'm still seeing "Accept- Encoding: gzip,deflate". Is this expected behavior? If so, is there a reason why I can't change the Accept-Encoding value? Thanks, -Andrew
[jQuery] jQuery 1.3: Sweet upgrade, but can we use it?
New blog post, "jQuery 1.3: Sweet upgrade, but can we use it?" here: http://tr.im/751a The gist is that I'm concerned that jQuery is progressing faster than users are upgrading their browsers, making it increasingly difficult for web developers to sell the use of the library to management and clients. I *hope* I'm wrong because I would love to take full advantage of the improvements in 1.3. I welcome your comments. -Andrew - http://andrew.hedges.name/blog/
[jQuery] Re: why is this code inefficient?
I suggest giving jQuery a more specific context in which to search for the elements in question. If the set of elements you want is (or can be put) inside an element with an ID, that is the most efficient. Selectors like: $('#some-element .a-bunch-of-elements') ...are way faster than selectors like: $('.a-bunch-of-elements') On Sep 25, 7:01 am, pedalpete <[EMAIL PROTECTED]> wrote: > I thought I was getting the hang of jquery and javascript, but then i > wrote this small function, and it is really taking a long to run - > like 15+ seconds. > > The purpose of the function is that i have a list of concerts ordered > by date. > I want to show the date when the date changes, so for all concerts on > Wed, Sep 24, I show the date as a heading on the first concert, and > then hide the rest of the date headings, and then for concerts on Thur > Sep 25, the date shows again on the first item, so users know they are > looking at a different day. > > This way users get a clear division of dates. > > the function I'm using is > [code] > function showDateDivides(){ > $('.divideDate').livequery(function(){ > var dividedID = $(this).attr('id'); > var dateTable = $('#'+dividedID).html(); > var splitDateTable = dateTable.split(' '); > var dayOfWeek = splitDateTable[0]; > var numOfMonth = splitDateTable[1]; > $('.dateTable#'+dividedID+':first').show(); > $('.dateTable#'+dividedID+':first > td#'+dayOfWeek).html(numOfMonth).addClass('firstDate'); > }); > [/code] > > the class divideDate is hidden in the css when the page loads, > The id holds the date formated in -mm-dd > the class dateTable holds a weekly view date table (so 7 squares), and > then the day of the week gets the date number and class of firstDate > added to it. > > I hope that's clear. Is this really inefficient code?
[jQuery] Re: best/standard way to benchmark your own scripts?
Someone is bound to have a better answer than this, but to get you started with profiling, have a look at this page where I include some code to time my script execution: http://andrew.hedges.name/experiments/simple-templates-speed-test/ It wouldn't be much of a stretch to apply this same pattern to individual parts of the script to get a more detailed view. That said, I'm pretty sure there are (commercial?) tools out there that let you profile scripts in some detail. I'd be interested to know, too, if there are any that are free software. -Andrew On Sep 17, 4:14 pm, Alex Weber <[EMAIL PROTECTED]> wrote: > looking to find possible bottlenecks and basically optimize the hell > outta my js which relies heavily on jquery and the occasional > plugin... > > is there a more elegant and efficient way to do this than to toss a > few document.write()s at my code?? =P > > thanks!! > > -Alex
[jQuery] Re: Docs down...really no mirror?
I'm building a Dashboard widget. It's not quite done, but it mostly works and it doesn't need 'net access because it contains a local copy of the docs. You can find it here: http://code.google.com/p/jquery-reference/ On Sep 6, 12:11 pm, Karl Swedberg <[EMAIL PROTECTED]> wrote: > Until it does ... > > http://www.learningjquery.com/2008/07/jquery-documentation-alternatives > > --Karl > > > Karl Swedbergwww.englishrules.comwww.learningjquery.com > > On Sep 5, 2008, at 7:32 PM, Evan Moran wrote: > > > > > I am also getting this right now. Any word on when this will come up? > > > On Sep 5, 4:04 pm, Sam <[EMAIL PROTECTED]> wrote: > >> The docs seem to be down again (and last night as far as I can > >> remember). > > >> Is there really no mirror?
[jQuery] Simple Templates
Introducing a new jQuery plug-in, Simple Templates: http://andrew.hedges.name/blog/2008/09/03/introducing-jquery-simple-templates One thing I have missed from my Prototype days (shudder, I know!) is simple, built-in templating. I know there are other templating plugins, but I liked the Prototype syntax, so I wrote my own. It's only 1009 bytes! Enjoy! -Andrew
[jQuery] UK salaries
Hi all, Can anyone provide guidance on ranges for salaries in the UK for experienced jQuery / JavaScript / UI programmers? Cheers, -Andrew