0

I have this code:

var browserName = "chrome";

    function getBrowserHack() {

        var browsersStack = {
            "chrome" : {
                "hacks": {
                    "global" : "!!window.chrome;",
                    "version" : {
                        "32" : "!!window.chrome && !!window.chrome.webstore;"
                    }
                }
            },
            "firefox" : {
                "hacks": {
                    "global" : "!!window.sidebar;",
                    "version" : {
                        "2": "(function x(){})[-6]=='x';"
                    }
                }
            },
            "safari" : {
                "hacks" : {
                    "global" : "/constructor/i.test(window.HTMLElement);"
                }
            },
            "opera" : {
                "hacks" : {
                    "global" : "window.opera && window.opera.version() == X;"
                }
            }
        }
        return $.getJSON(browsersStack, function(data){
            var browsers = data[browserName];
            return browsers;
        });
    }

i need to return function with this JSON data, and i have an error [object%20Object] 404 (Not Found). What i'm doing wrong?

0

2 Answers 2

2

I think you misunderstood getJSON, you have the JS Object already right there in your code, try this:

function getBrowserHack(browserName) {

    var browsersStack = {
        "chrome" : {
            "hacks": {
                "global" : "!!window.chrome;",
                "version" : {
                    "32" : "!!window.chrome && !!window.chrome.webstore;"
                }
            }
        },
        "firefox" : {
            "hacks": {
                "global" : "!!window.sidebar;",
                "version" : {
                    "2": "(function x(){})[-6]=='x';"
                }
            }
        },
        "safari" : {
            "hacks" : {
                "global" : "/constructor/i.test(window.HTMLElement);"
            }
        },
        "opera" : {
            "hacks" : {
                "global" : "window.opera && window.opera.version() == X;"
            }
        }
    }
    return browsersStack[browserName];
}

// Now get the browserhack by calling:
var browserHack = getBrowserHack('chrome');
Sign up to request clarification or add additional context in comments.

1 Comment

Had a huge typo in there, fixed it just now
0

getJSON is an Ajax function. It makes an HTTP request to a URL (the first argument) and processes the response with the function used in the second argument.

You don't even have any JSON. You just have an object.

// Remove this line
return $.getJSON(browsersStack, function(data){
// Keep these two lines
    // but use the correct variable name here - you aren't copying the object to data
    var browsers = browsersStack[browserName];
    return browsers;
// Remove this line
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.