0

I've following query string:

url = "http://56.177.59.250/static/ajax.php?core[ajax]=true&core[call]=prj_name.contactform&width=400&core[security_token]=c7854c13380a26ff009a5cd9e6699840"

I want to get the value of variable core[call] i.e. prj_name.contactform

How should I get this value using jQuery/javascript?

Please help me.

1
  • @adeneo:I asked the question here because I want value of a variable from query string which is itself in array format. I don't know how to get such kind of variable from query string. That's why I'm asking for help. So I'm kindly requesting you to please remove the "Duplicate" mark. Commented Dec 31, 2014 at 14:01

1 Answer 1

0

Try this, which puts all variables into the vars{} object. You can then access vars.core.ajax, vars.width, etc. Also live on this fiddle:

var u = "http://localhost:8080/static/ajax.php?core[ajax]=true&core[call]=prj_name.contactform&width=400&core[security_token]=c7854c13380a26ff009a5cd9e6699840&x=1"
var re = /(\w+)\[(\w+)\]$/
var vars = {}
u.split('?')[1].split('&').forEach(function(e) {
    var p = e.split('=');
    var v = p[0].match(re);

    if (v === null) {
        vars[p[0]] = p[1];
    } else {
        if (!(v[1] in vars)) { vars[v[1]] = {}; }
        vars[v[1]][v[2]] = p[1];
    }
});
console.log(vars);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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