Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined variables in jquery.atmosphere.js #347

Closed
hpihkala opened this issue May 8, 2012 · 5 comments
Closed

Undefined variables in jquery.atmosphere.js #347

hpihkala opened this issue May 8, 2012 · 5 comments

Comments

@hpihkala
Copy link

hpihkala commented May 8, 2012

If I add a custom header for the request and define it as a function, like this:

        var request = { 
                /* ... */
                headers: {
                    c: function() {
                        return counter;
                    }
                }
        };

jquery.atmosphere.js fails in function _attachHeaders(request):

                jQuery.each(rq.headers, function(name, value) {
                    var h = jQuery.isFunction(value) ? value.call(this, ajaxRequest, request, create) : value;
                    if (h) {
                        url += "&" + encodeURIComponent(name) + "=" + encodeURIComponent(h);
                    }
                });

Where it tries to call the function with parameters (this, ajaxRequest, request, create). As far as I can see both ajaxRequest and create are undefined and the browser throws an error.

Variables with these names are not available even in the functions that _attachHeaders() is called from, so maybe they are some old stuff from before the rewriting of the jquery plugin? Maybe they can just be removed from the function call?

Best regards,
Henri

@hpihkala
Copy link
Author

hpihkala commented May 8, 2012

You should also change the line

if (h) {

to

if (h!=null) {

Because the value of h might well be a valid value of 0, which evaluates to false and does not get added.

@hpihkala
Copy link
Author

hpihkala commented May 8, 2012

All of the above was in _attachHeaders(request). Actually a similar piece of code exists in function _doRequest(ajaxRequest, request, create) where the variables ajaxRequest and create DO exist.

However the comment about the "if (h)" applies to _doRequest() function also!

@jfarcand
Copy link
Member

jfarcand commented May 8, 2012

Can you do a pull request so I can integrate easily your proposal? If not, just cut an paste a diff -u to this thread. Thanks

@jfarcand
Copy link
Member

jfarcand commented May 9, 2012

Testing the fix.

@jfarcand
Copy link
Member

jfarcand commented May 9, 2012

Integrated. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants