Re: [jQuery] Re: How to update the content of an XML node with JQuery

2009-12-01 Thread Nick Fitzsimons
2009/12/1 Michel Belleville :
> I'm not sure you can even do that with jQuery the way you'd like to do it.
>
> Is it so important to use xml for medium ?
>
> Michel Belleville
>
>
> 2009/12/1 karthick 
>>
>> Hi Michel,
>>
>>          Thank you very much for pointing that, now its clear why it
>> wasn't updating. But can you give me some idea on how I can achieve
>> this functionality. I just want to manipulate the xml at client side
>> using jquery and finally send it back to the server as string. I was
>> trying with append() and replaceWith() function in vain!! :(
>> I would like to do it with Jquery because i need some browser
>> compatibility. Is this really possible with jquery?
>>

If you have a reference to an XML DOM, you can send that using the
XMLHttpRequest object's send() method [1], [2]. I don't know if jQuery
supports having a DOM passed to its Ajax methods though.

Regards,

Nick.

[1] <https://developer.mozilla.org/en/XMLHttpRequest#send()>
[2] <http://msdn.microsoft.com/en-us/library/ms763706(VS.85).aspx>
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


Re: [jQuery] Javascript Array question

2009-11-13 Thread Nick Fitzsimons
2009/11/13 Atkinson, Sarah :
> I want to create an 2D array that would basically contain a variable amount
> of 3 entry arrays. Is there a short way of doing this? Like
> var myArray= new Array( ,3);

JavaScript doesn't support multi-dimensional arrays, so you'll have to
work with a single-dimensional array of single-dimensional arrays.

Furthermore, JavaScript allows for arrays to be dynamically resized,
so you can specify the convention that your arrays should be of length
3, but the language will not enforce that constraint.

For example:

var example = [
   [0, 1, 2],
   [4, 5, 6],
   [7, 8, 9]
];
// that gives us an array containing three arrays, each of length 3
alert(example[0][0]); // alerts "0"
alert(example[1][2]); // alerts "6"

example[0][749] = "Foo";
alert(example[0].length); // alerts "750"

alert(example[0][2]); // alerts "2"
alert(example[0][3]); // alerts "undefined"
alert(example[0][748]); // alerts "undefined"
alert(example[0][749]); // alerts "Foo"


Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


Re: [jQuery] Just discovered something

2009-10-29 Thread Nick Fitzsimons
2009/10/29 waseem sabjee :
> The most likely reason is that do is a JavaScript "Key Word"
>
> On Thu, Oct 29, 2009 at 12:53 PM, lionel28  wrote:
>>
>> I am sure most of you guys already know it, but I just found out that IE
>> does
>> not like the word "do"
>>
>> I was doing an ajax called and I had
>>
>>        data: {
>>        do : "uploadgame"
>>
>> and I kept on getting that error
>>
>> expected identifier, string or number,
>>

As Waseem points out, the error was due to "do" being a JavaScript
keyword. You don't state in which browser(s) it worked correctly, but
I would bet it was a recent version of Firefox: it will also cause an
error in Chrome, and probably in Safari and Opera too.

The reason it will work in recent builds of Firefox is that they
already incorporate some changes which are due to arrive in the
ECMAScript version 5 specification next year, which will allow such
reserved words to be used in that context.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: this.remove

2009-10-19 Thread Nick Fitzsimons

2009/10/19 Krommenaas :
>
> I was wondering why in a link's click event...
>  $('a.').click( function() {
>
> this won't work...
>   this.remove()
>
> but this does work...
>  $('#'+this.id).remove();
>
> as will this...
>    $('a[name='+this.name+']').remove();
>
> It's not a problem since I have these work-arounds, I'm just trying to
> understand why this.remove() doesn't work. Tia.
>

Because "this" in an event handler is a reference to the DOM node that
is the target of the event, not a jQuery object.

$(this).remove();

should work.

Relevant jQuery docs: <http://docs.jquery.com/Events/click#fn>

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: jQuery speed seems slow

2009-10-15 Thread Nick Fitzsimons

2009/10/14 James :
>
> Unless your DOM tree is huge and you're trying to select something
> massive in one go, the performance difference between a simple jQuery
> ID selector (e.g. $("#myID")) vs. a native getElementById selector
> should be very negligible, because jQuery uses that same native
> selector.
>

"Negligible" is a bit strong; an examination of the jQuery selector
code shows that, although it is well optimised for the simple ID
selector, it will nonetheless do the following for $("#foo"):

1. do a logical OR detecting the presence of a selector,
2. test for the presence of a nodeType property on the selector,
3. branch over an if clause (see step 9) when that test fails,
4. compare the type of the selector with "string" and enter an if clause,
5. execute a match using a regular expression,
6. test that the match array is not null and that it has a value at a
specific position in the match array and that no context argument was
passed,
7. test the same position in the array and branch to an else clause,
8. finally execute getElementById, then recursively call itself
causing it to repeat steps 1 and 2, where it will enter the if clause,
9. set a few properties on itself,
10. return itself from the recursive call,
11. return the value received from the recursive call to your code.

Clearly that's quite a bit of overhead; if all you actually need is a
reference to the DOM element itself, using getElementById directly is
always going to be faster.

Even if you want the DOM element to be wrapped in the jQuery object,
it is much more efficient to replace

var foo = $("#foo");

with

var foo = $(document.getElementById("foo"));

as that will get to step 2 above, drop into the if clause (step 9) and
return, avoiding a RegExp match, assorted bits of logic and property
testing, and a recursive function call.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: tag not readable in MSIE

2009-10-13 Thread Nick Fitzsimons

2009/10/13 V :
>
> The foklowing code works fine in Firefox, but not in MSIE;
> var title = $("title").text();
>
> I want to know the blabla as you can see. But MSIE does
> not support this.
> Is there another solution for this?
>

var title = document.title;


Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: IE7 does not play nice with $.load

2009-10-02 Thread Nick Fitzsimons

2009/10/2 brian :
>
> On Fri, Oct 2, 2009 at 5:00 AM, Nick Fitzsimons  wrote:
>>
>> 2009/10/2 Dave Methvin :
>>>
>>>> Is there some easy way of forcing IE to make ajax
>>>> calls?
>>>
>>> You can use the old trick of adding a random number to the end of the
>>> url.
>>
>> That's what the { cache: false } option does; see jQuery 1.3.2 line
>> 3448 onwards:
>>
>> if ( s.cache === false && type == "GET" ) {
>>    var ts = now();
>>    // try replacing _= if it is there
>>    var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
>>    // if nothing was replaced, add timestamp to the end
>>    s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") +
>> "_=" + ts : "");
>> }
>>
>
> Could someone please explain to me the significance of "_=" in the URL?
>

It doesn't really have any significance as such, it's just a throwaway
name. In order to break browser caching, something needs to be added
to the query string which wasn't present on any previous request from
the same browser, and jQuery uses the current time in milliseconds
since the epoch date. A query string might already be present, with
various name-value pairs representing form elements (e.g.
http://example.com/foo?id=1&bar=baz). However, there is very little
chance somebody has a form element named "_", so that is used as the
name for the otherwise-irrelevant timestamp used to break caching; in
the previous example, the URL would change to something like
http://example.com/foo?id=1&bar=baz&_=987654321.

The only circumstances in which this could break is if somebody
already has a form element named "_", in which case the behaviour of
the server when faced with two values for the same field is
implementation-dependent (it's best if it makes an array of them, but
PHP for example is broken in this regard); or if an over-eager
server-side developer throws a validation error on encountering a
field they weren't expecting, in which case said developer should be
sent off to grow turnips for a living instead.

Regards,

Nick.

-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: IE7 does not play nice with $.load

2009-10-02 Thread Nick Fitzsimons

2009/10/2 Dave Methvin :
>
>> Is there some easy way of forcing IE to make ajax
>> calls?
>
> You can use the old trick of adding a random number to the end of the
> url.

That's what the { cache: false } option does; see jQuery 1.3.2 line
3448 onwards:

if ( s.cache === false && type == "GET" ) {
var ts = now();
// try replacing _= if it is there
var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");
// if nothing was replaced, add timestamp to the end
s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") +
"_=" + ts : "");
}

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Each function gives errors in IE6

2009-09-24 Thread Nick Fitzsimons

2009/9/24 Shane Riley :
>
> Weird double post. Found the issue. For some reason declaring the
> variable worked. So I changed it to:
> var  top = (parseInt($(this).height()) / 2) - 6;
>

That's because "top" is already defined as a synonym for the top-level
window object, and IE gets upset if you try to overwrite it.

I think you'd get the same "Not implemented" error if you tried to
assign values to the global "self", "parent", and "window" properties
too. Assuming you're not running in a frame or an iframe, "self",
"top", "parent", and "window" all refer to the same object. In a frame
or iframe, "self" and "window" will refer to the framed document's
"window", and "top" will refer to the "window" object of the very
topmost document, while "parent" will refer to the "window" object of
the document containing the frame, which is not the same as "top" if
you have nested frames/iframes.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Browser sniffing - the correct way?

2009-09-21 Thread Nick Fitzsimons

2009/9/21 RobG :
>
> On Sep 18, 1:32 am, ldexterldesign  wrote:
>
>> A
>> friend of mine just recommend:http://www.quirksmode.org/js/detect.html
>
> Don't use it. Don't even consider detecting specific browsers for
> javascript quirks. For HTML or CSS hacks, go to relevant forums. Often
> the best solution is to simply avoid troublesome features.
>

Also, take note of ppk's further comments linked to from that browser
detection page; although he wrote them quite a few years ago (as
evidenced by references to IE 3 and Navigator 2), they are good
advice: <http://www.quirksmode.org/js/support.html>

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Browser sniffing - the correct way?

2009-09-18 Thread Nick Fitzsimons

2009/9/18 ryan.j :
>
>> comes to supporting CSS correctly. What exactly do you mean by
>> "negative vertical span margins"?
>
> i'd hazard a guess he meant something along the lines of...
>
> span { margin: -12px 0 0 0; }
>

That's what was confusing me. Opera handles negative margins perfectly
well and has done for years - the only browser I'm aware of that can
have major problems with them is IE6 (and possibly 7).

-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Browser sniffing - the correct way?

2009-09-17 Thread Nick Fitzsimons

2009/9/17 ldexterldesign :
>
> Thanks for your responses guys. I actually need to detect the Opera
> browser and serve up a load of new CSS. Opera doesn't support negative
> vertical span margins, so I'm gonna have to reduce the font-size of
> some text.
>

As a general rule, Opera is one of the most reliable browsers when it
comes to supporting CSS correctly. What exactly do you mean by
"negative vertical span margins"? Whatever it is, if it's something
that can reasonably be expected to work cross-browser (in that it is
valid according to the relevant web standards, rather than relying on
undefined behaviour in a few browsers) then I'd be extremely surprised
to find that Opera didn't support it.

If you can explain what you're trying to do I would imagine somebody
can help. Hacks and browser-specific code should always be avoided
except as an absolute last resort.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Ajax - Access data arguments in callback

2009-09-17 Thread Nick Fitzsimons

2009/9/17 Flamer :
>
> Hello,
>
> Is it possible to access the data arguments that are sent with the
> ajax function?
>
> Example:
> $('#mycheckbox').click( function() {
>        $.get( '/ajax.php', { nr: this.id }, function( data, textStatus ) {
>                // Here I want to access the arguments I just sent with 
> ajax.php
>
>                // As example, something like this:
>                $('#'+arguments.nr).attr('checked', 'checked');
>        } );
>
>        return false;
> } );
>

If I understand you correctly, then assigning your data object to a
variable which can be accessed via a closure in the callback function
would do it - something like:

$('#mycheckbox').click( function() {
   var sentData = { nr: this.id };
   $.get( '/ajax.php', sentData, function( data, textStatus ) {
   // Here I want to access the arguments I just sent with ajax.php

   // As example, something like this:
   $('#'+ sentData.nr).attr('checked', 'checked');
   } );

   return false;
} );

should be all you need.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: IE 8 chokes on HTML5 elements inserted with jQuery

2009-09-15 Thread Nick Fitzsimons

2009/9/15 Perceptes :
>
> I've encountered a problem with the combination of jQuery, IE, and
> HTML5 elements. HTML5 elements inserted into the page after initial
> load via jQuery's DOM manipulation functions are not parsed correctly
> by IE, even with Remy Sharp's HTML5 shiv script.
>

The problem is that jQuery uses innerHTML, rather than DOM methods, to
insert the new content (which is why it's passed to jQuery as a
string). This means it relies on IE's HTML parser to correctly parse
the markup from the string when it is inserted.

When IE's parser encounters an element it doesn't recognise the name
of, it creates the element as an empty element (similar to  or
), then parses the content as if it were sibling nodes, then
creates an empty element whose name begins with a slash (/ARTICLE for
example); you can see this on your test page by clicking on the "IE
fail" button and then entering:

and

in the location bar; the first will show "ARTICLE", and the second
will show "/ARTICLE".

To work around this you basically have two options:

1. Before any other script is executed, add the line:
document.createElement("article");
and add equivalent lines for any other HTML5-specific elements you
wish to use (such as section). This prompts IE's HTML parser to expect
blocks with that tagName and it will then parse them correctly.

2. Don't use jQuery's innerHTML-dependent approach to creating new
content; instead, use DOM creation methods directly, for example:

var article = document.createElement("article");
var header = article.appendChild(document.createElement("header"));
header.appendChild(document.createTextNode("Hello World");

var container = document.getElementsByTagName("div")[0];
container.insertBefore(article, container .getElementsByTagName("h2")[1]);

... and so on. (Actually, you can use jQuery for selecting the correct
insertion point and for inserting the new elements there, as jQuery
can cope with elements when inserting content.)

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Ajax not working in Firefox

2009-09-10 Thread Nick Fitzsimons

2009/9/10 Karl Hungus :
>
> I can see the form data in the body of the post too, using both Live
> HTTP Headers and Charles. Which I guess only confuses me more. :-)
>
> One thing I did notice, is the Content-Type attribute of the request
> header has "application/x-www-form-urlencoded; charset=UTF-8" for FF3,
> but only "application/x-www-form-urlencoded" for FF2. I wondered if
> that difference might be  causing something strange to happen at the
> server end.
>

If the server developer (or the library being used on the server) is
matching on the precise ContentType
"application/x-www-form-urlencoded" (without the charset specifier) as
a way of determining whether or not to parse the request body, then
that is a bug: section 14.17 of RFC 2616
<http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17>
makes it clear that the version sent by FF3 is a valid form of the
header.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Ajax not working in Firefox

2009-09-09 Thread Nick Fitzsimons

2009/9/9 RPrager :
> FF3 output:
>
> logcgisCan not access CGI data:  Script can only
> be used to decode form results
> There are 0 positional parameters and 0 CGI fields
> 
>
> FF2/IE output:
>
> logcgis
> There are 0 positional parameters and 2 CGI fields
> CGI 'F10' equals 'Yes'
> CGI 'F11' equals 'No'
> 
>

At this stage I would suggest digging into the actual HTTP traffic,
not with Firebug (which, being inside the browser, doesn't necessarily
give an accurate view of things) but with an HTTP debugging proxy. If
you're on Windows you can use Fiddler
<http://www.fiddler2.com/fiddler2/>; on other platforms (as well as
Windows) the trial version of Charles <http://www.charlesproxy.com/>
is worth a look.

Enable one of these tools (you have to install a Firefox extension for
each of them to autoconfigure - both their sites make this stuff easy
to find) and you'll be able to see the actual content of your request.
If the body of the request contains the form data then the problem is
on the server; if not, then the problem is on the browser. If the
problem is on the browser then more digging will be required, but if
it's on the server then the information about the whole request
(headers and body) will help the server-side developer work out what's
going on.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: HTML code inside script tag, how access to it with DOM???

2009-09-09 Thread Nick Fitzsimons

2009/9/9 Mariano :
>
> I have an HTML page that looks like this:
>
> 
>   
>    
>       
>           <div id="test">some test</div>
>       
>    
> 
>
> Now I have the will to access to the text inside test div but the code
> $('#test').text();
> doesn't work, matter of fact nothing is returned.
>
> If my div is dragged outside of script tag, js code return me "some
> test" correctly, but alas, div MUST be inside script.
>

That isn't valid HTML; even if you manage to get it to work in one
browser, it may well behave differently in others. A script element
can only contain script code:
<http://www.w3.org/TR/html401/interact/scripts.html#edef-SCRIPT>

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Fade-in problem in IE7(urgent)

2009-09-08 Thread Nick Fitzsimons

2009/9/8 rupak mandal :
> hi nick,
> Thanks for quick reply.
> That's not the problem. Here is the full code.
>

It looks like jQuery's fadeIn is setting the opacity to the empty
string (on IE only) at the end of the animation. You could try using
fadeTo instead <http://docs.jquery.com/Effects/fadeTo>:

$(document).ready(function(){
$(".div1").fadeTo(5000, 0.5);
})

but I haven't tested that.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Fade-in problem in IE7(urgent)

2009-09-08 Thread Nick Fitzsimons

2009/9/8 Rupak :
> http://jsbin.com/icatu
>

It doesn't help that your HTML is wrong:



You aren't closing the div: you need 

Don't know if this will fix your original problem, but it can't hurt to try :-)

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Ajax not working in Firefox

2009-09-08 Thread Nick Fitzsimons

2009/9/4 RPrager :
>
> Here is the only difference I found in the Request Headers:
>
> FF2: Content-Type    application/x-www-form-urlencoded
>
> FF3: Content-Type    application/x-www-form-urlencoded; charset=UTF-8
>
> Any ideas?

One definite possibility is that the server-side component is failing
to cope with the (perfectly valid) inclusion of the charset
information in the Content-Type request header. Check with the
developer responsible that he isn't doing something silly like (in
pseudo-code):

if (Request.ContentType == "application/x-www-form-urlencoded") //
then do the form parsing

as this would cause the problem you are seeing, and is also a broken
way of parsing a request.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Anything wrong with this ajax syntax?

2009-09-08 Thread Nick Fitzsimons

2009/9/8 Rick Faircloth :
> Is there something missing that would keep it from functioning?
>

No, but there's something _extra_ that will keep it from functioning ;-)

>  $.ajax = ({ cache: false,
>

That equals sign means that you are assigning a new value to $.ajax -
to be precise, the result of the expression on the right hand side of
the equals sign, which in your case is returning an object.

I think you want

$.ajax({ cache: false,
...

which will invoke the jQuery ajax method with your object as an argument.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: not returning a JSON object

2009-09-01 Thread Nick Fitzsimons

2009/8/27 defdev :
> from the server side:
>
>  echo '{ message: "why wont this work" }';
>

That isn't valid JSON. According to the JSON spec <http://json.org/>,
the name part of a name: value pair needs to be quoted with double
quotes, and a strict JSON parser will enforce this. Changing it to

echo '{ "message": "why wont this work" }';

will fix it.

Of course this may not actually fix your problem - I'm not sure how
strict jQuery is about enforcing JSON parsing rules - but fixing it
will eliminate one possible point of failure.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: $.each cannot iterator my array

2009-08-28 Thread Nick Fitzsimons

2009/8/28 davidshe...@googlemail.com :
> i have an array initialized like
> var myArr = new Array();
>
> later I use
>
> myArray['somestring'] = new Array();
> myArray['somestring'].push(mydata);
>
> to create and new array inside of it, and populate my data by pushing.
> Then I want to use the jQuery.each(...) to iterator over it, like this
>
> $.each(myArray, function(){
> alert(this);
> });
>
> But I found the jQuery does not event enter the loop. What's wrong
> with my array?
>

Your outermost array isn't being used as an array, it's being used as
an object with named properties. As explained in the first paragraph
of <http://docs.jquery.com/Utilities/jQuery.each>, $.each will see
that it is an array, and try to iterate over its elements by numeric
index, but as its length is zero, there aren't any.

Change your outermost array to an object, and it should work:

var myStuff = {};
myStuff['somestring'] = [];
myStuff['somestring'].push(1);
myStuff['somestring'].push(2);
myStuff['somestring'].push(3);

$.each(myStuff, function(key, value) {
alert(key + ": " + value); // shows "somestring: 1,2,3"
});

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: How to cancel an AJAX request?

2009-08-26 Thread Nick Fitzsimons

2009/8/26 Hector Virgen :
> Thanks, Rupak, but I was hoping to be able to accomplish this without a
> plugin. What I'm thinking of doing is storing the XMLHttpRequest object as a
> local variable early on, like in the beforeSend callback.

No need to make it so complex; from <http://docs.jquery.com/Ajax/jQuery.ajax>:

"$.ajax() returns the XMLHttpRequest that it creates. In most cases
you won't need that object to manipulate directly, but it is available
if you need to abort the request manually."

So just do something like:

xhr = $.ajax(blah);

and when you want to abort the request, use

xhr.abort();

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Problem with Ajax Cross-Domain

2009-08-25 Thread Nick Fitzsimons

2009/8/24 Alexander Cabezas :
> When i try to make an ajax request like:
> $.get( "http:localhost:3001/account/create.json", SignUp.onComplete );
>
> I get the following error in the firebug ( Net ):
> OPTIONS - 405 Method Not Allowed
>
> Is it related to cross-domain request?.
>

Probably not, assuming you aren't making a cross-domain request. That
error is the server tellling you that you aren't allowed to use GET to
access the resource at that URL [1]. Looking at it, it probably only
allows POST.

[1] <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.6>

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: setInterval()

2009-08-24 Thread Nick Fitzsimons

2009/8/23 solow :
> function joinRoomFunction(roomId){
>        $("#tables").load("pages/pages.php", {r: roomId}, function()
> {
>                $("#myTable").tablesorter({widgets: ['zebra']});
>                alert('loaded');
>                 $('button#stopINTERVAAL').click(function()
> {intvarM=clearInterval(intvarM);});
>        });
>        }
>    function joinRoom(roomId){
>        var intvarM=window.setInterval("joinRoomFunction("+ roomId
> +")",5000);
>    }

A few points: you are assigning the interval identifier to intvarM
inside a function using "var intvarM = setInterval...". The use of the
"var" keyword will make that variable local to that function. You need
to declare the variable in some outer scope, so that it is also
visible in the click handler you assign to the button.

Also, clearInterval does not return a value (or, to be absolutely
precise, the return value of clearInterval is "undefined"), so there
is probably no point assigning it to anything.

Finally, by assigning a string to setInterval you are basically
performing an "eval", which is very inefficient. Creating a function
reference using a closure is the preferred approach.

Try this:

var intvarM; // as this is declared out here, it will be visible to
all the functions below

function joinRoomFunction(roomId){
$("#tables").load("pages/pages.php", {r: roomId}, function() {
$("#myTable").tablesorter({widgets: ['zebra']});
alert('loaded');
$('button#stopINTERVAAL').click(function() {
window.clearInterval(intvarM); // this method returns undefined
});
 });
}

function joinRoom(roomId){
    intvarM = window.setInterval((function(roomId) {
return function() { // return a function to be used by the timer
joinRoomFunction(roomId);
}
})(roomId), 5000);
}

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: event handlers that run after the browser's default action

2009-08-21 Thread Nick Fitzsimons

2009/8/20 Tom Worster :
>
> is there a way to set up a page so that a event handler function is bound to
> a DOM object and event but it runs _after_ the browser's default action is
> complete?
>

No; the DOM Events specifications explicitly state that the event
handling process occurs before the default action of the browser. For
example, DOM Level 2 Events section 1.2.4 [1] states:

"...the DOM implementation generally has a default action associated
with the event. An example of this is a hyperlink in a web browser.
When the user clicks on the hyperlink the default action is generally
to active that hyperlink. *Before processing these events*, the
implementation must check for event listeners registered to receive
the event and dispatch the event to those listeners. These listeners
then have the option of canceling the implementation's default action
or allowing the default action to proceed."

DOM Level 3 Events section 1.3 [2] is even more explicit:

"The default actions *are not part of the DOM Event flow*. Before
invoking a default action, the implementation must first dispatch the
event as described in the DOM event flow."

[my emphasis in both extracts]

So I'm afraid your out of luck on that :-(

[1] 
<http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-flow-cancelation>
[2] 
<http://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Events-flow-cancelation>

(BTW, I'm curious as to why you would ever need to do this - I suspect
that if you state the actual problem you're trying to solve, rather
than the mechanism you thought might help you solve it, then somebody
can probably suggest a different approach which will "Just Work".)

Cheers,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Printing JQuery Tutorials?

2009-08-13 Thread Nick Fitzsimons

2009/8/13 Richard D. Worth :
> Good idea. We've done that now.
> - Richard
>
> On Thu, Aug 13, 2009 at 6:58 AM, derek  wrote:
>>
>> Thanks!  Maybe they should just alter the button to generate
>> this type of URL?

Rather than all this mucking about with special URLs and having to
follow links to a "Printable version", why doesn't somebody just make
the appropriate modifications to the print stylesheet at
<http://docs.jquery.com/skins/common/commonPrint.css>? That's what
it's for, after all ;-)

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: AJAX calls acting syncronously

2009-08-11 Thread Nick Fitzsimons

2009/8/11 sak :
>
>
> Thats the thing, I don't want the results coming back in order. I am
> trying emulate them coming back unordered, but they are coming back
> ordered. I was digging deeper yesterday and discovered the results are
> linked to an aspsessionid cookie that is created from the asp pages
> (don't fully understand it yet) but through elimination I determined
> if I delete this cookie everytime it is generated, then the AJAX calls
> behave normally - the calls work asyncronously. If the cookie exists
> then the AJAX calls act syncronously which is not what I want. If
> anybody has any experience in this.
>

I assume you're using Classic ASP rather than ASP.NET? If so, the
reason your first (10s) call delays the response to the second (1s) is
that ASP's session tracking is enabled by default, and its session
object does not support concurrent access by multiple threads. Thus,
when the server starts a thread to handle the second (1s) request,
that thread is blocked waiting for the session object associated with
your client (via the session cookie) to be released by the first (10s)
request's thread. So this is just an effect of a limitation in the
server-side technology, and nothing to do with the browser or jQuery.

You can disable session tracking for your tests using the
@ENABLESESSIONSTATE directive:
<http://msdn.microsoft.com/en-us/library/ms525847.aspx>.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Sloppy Documentation of Ajax Methods

2009-08-10 Thread Nick Fitzsimons

2009/8/10 Shawn :
>
> ALL the functions (load, get, post, etc) are wrappers for the $.ajax()
> function.  I only use $.ajax() now and tweak it to meet my needs... Makes
> for less confusion.
>
> Ajax by default will only load files that are in the same domain as the
> calling page.  This is a browser security feature.  (Use $.ajax() and jsonp
> to work around that.)  So the getScript() function will follow this
> limitation as well if it is calling the new script via Ajax.

getScript() and get() requesting JSONP are the odd ones out - the
ajax() method detects these cases and loads them by creating a

[jQuery] Re: JQuery and XHTML in Firefox

2009-07-28 Thread Nick Fitzsimons

2009/7/28 ScottSEA :
>
> I've undergone the process to convert to XHTML - all is valid and all
> is well... but no.  Firefox treats XHTML as XML.  jQuery is designed
> for HTML - when appending / prepending / removing it uses the innerHTML
> () function, which of course doesn't work for XML/XHTML.
>

Where isn't it working? I've just checked on an XHTML page, served
with Content-Type "application/xhtml+xml", parsed in Strict Mode on
Firefox 3.5.1 and the line:

document.getElementById("log").innerHTML = "Fred"

worked just fine.

I've also used jQuery on other XHTML pages and it worked just fine.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: order of ajax calls

2009-07-21 Thread Nick Fitzsimons

2009/7/21 András Csányi :
>
> Okay. You are right and the options what you mentioned likes form me,
> but I asked hungarian web developers and they sad I have a third
> option:
> using ajaxSetup llike this:
> $.ajaxSetup({
>  async: false
> });
> The problem what I see in this case that ajaxSetup working globally
> and after async calls I have to set back to sync.

Disabling async is a terrible idea. Disabling it because of a slow
server is even worse. It will cause the browser to freeze until the
result comes back from the server. It guarantees a terrible user
experience.

You can achieve what you want by storing a reference to the callback
function in a variable, then changing that variable to hold a
reference to a different function when the appropriate conditions are
satisfied. I have an example at
<http://www.nickfitz.co.uk/examples/javascript/switching-functions.html>
although it's pure JavaScript, not jQuery; the code is all in the page
(not what I'd usually do, except for examples like this) so you can
view the source to see what it's doing.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: animation is getting slower.

2009-07-17 Thread Nick Fitzsimons

2009/7/17 weidc :
> this is my code (js):
> $("#boden").mousemove(function(e)

>
>                $(this).click(function()

> it is just moving a little div in an other div to the point where you
> clicked. it works pretty well but after 20-30 clicks the animations
> takes some time to fire again and i wonder why. someone got an idea?
>

You appear to be adding a new "click" event handler on every
"mousemove" event. After a few seconds of moving the mouse you will
have added hundreds, if not thousands, of event handlers. Obviously,
they'll take a little while to execute, even though they all do the
same thing...

Cheers,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Detecting a redirect response to an Ajax query

2009-07-16 Thread Nick Fitzsimons

2009/7/16 Nick Fitzsimons :
> 403 Forbidden [1]

Oops, forgot the link :-(

[1] <http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.4>


-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Detecting a redirect response to an Ajax query

2009-07-16 Thread Nick Fitzsimons

2009/7/15 candlerb :
>
> The login page gets inserted into the DOM, so I know the client must
> be chasing the redirect and I must be getting either "success" or
> "notmodified" in status. Looking at jQuery source, this comes from
> xhr.status (in function httpSuccess) which gives "success" for 2xx or
> 304, so any 3xx redirect code must have been followed and lost.
>
> I can check for xhr? at the server side, and if so, instead of
> redirecting to the login page I can send back some sort of uncommon
> HTTP error which can be detected, e.g. 410 Gone, or a custom HTTP
> header. I'll have a play along those lines.
>

The XMLHttpRequest object transparently follows 3xx redirect
responses, so your idea of detecting the situation on the server is
the way to go. As James has pointed out, the X-Requested_With header
is your best bet.

If you intend to send a client error code then you're probably best
with 403 Forbidden [1]; then you can include an appropriate message
for the user, with a link to the login page, as the body of the
response (aka "the entity"):

"If the request method was not HEAD and the server wishes to make
public why the request has not been fulfilled, it SHOULD describe the
reason for the refusal in the entity."

It's slightly stretching the interpretation of "The server understood
the request, but is refusing to fulfill it. Authorization will not
help and the request SHOULD NOT be repeated" to use 403 in this case,
but I think it can be justified, in that the application is being told
not to attempt authorization, and can instead inform the user that
_they_ will have to attempt authorization by logging back in to start
a new session.

You might also consider adding a query string parameter to the login
link (e.g. the id of the expired session) that allows the application
to be re-initialised to the state it was in at the time of the failed
Ajax request once the user has established the new session, as this
will make things a bit easier on the user. On the other hand, this may
be unnecessary, overkill, or just too complex to be worth doing,
depending on your application.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: why is this href firing???

2009-07-09 Thread Nick Fitzsimons

2009/7/9 Jan Limpens :
> in fact, it was a button at first, but it always submitted :)
> I ought to switch that back :)
>

As long as you specify the type, it should be fine. If you don't, the
default type is "submit", so you must explicitly use:
button content

IE gets this wrong and has a default type of "button", just to confuse
matters ;-)

HTH,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: parseerror on GET from window.location

2009-06-19 Thread Nick Fitzsimons
2009/6/18 jacktanner :
>
> I'm trying to do an AJAX GET.
>
>            var q_url = window.location.toString();
>            $.ajax({
>                type: 'GET',
>                        url: q_url,
>                        cache: false,
>                        dataType: 'json',
>                        success: function(response, textStatus) { ... },
>                        error: function (xhr, textStatus, errorThrown) {
>                          alert(textStatus);
>                        }
>            });
>
> This triggers the error callback with textStatus == "parseerror".

You're specifying a dataType of "json", yet you're GETting the
original HTML page in which this code is running (window.location). As
HTML is not JSON, you should _expect_ a parse error.

Regards,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/


[jQuery] Re: Error in IE - Error: 'url' is null or not an object

2009-06-18 Thread Nick Fitzsimons

2009/6/18 Heather :

In
> http://heather101.com/jcarousel/scentsy/scentsy.js
you have a trailing comma after the final element in the
"mycarousel_itemList" array. Most browsers will ignore that, but it
causes IE to add an extra "undefined" element at the end of the array,
increasing the array's length by 1. Remove that comma and it should
work.

Cheers,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/