[Solved] How can i target javascript variable using jquery?


If you need to access your json object “userData”, you’ll want to add the following in your click function:

var country = userData['country'];  
var region = userData['region']; 

and so on.

You could send the whole object without separation if you plan on sending it via AJAX. Below is an example of this:

$(function() {
    var userData = {"country":"null","region":"","timezone":"null","key":"sessionSecret","browser":"Chrome","bversion":"0.0","loggedIn":"false"};
    $('#regbtn').click(function() {
        $.ajax({
            url: "someURL",
            data: userData,
            type: "POST",
            cache: false,
            dataType: "json"
        }).done(function(data, textStatus, jqXHR) {
            // check if response was valid/invalid or do other stuff here 
        });
    });
});

5

solved How can i target javascript variable using jquery?