BrodaTherapy
BrodaTherapy

Reputation: 91

Passing a variable to jquery via url from PHP

I need a bit of help with PHP and JQuery. How would I go about passing a variable from PHP to JQuery while at the same time redirecting to another page that accesses the JQuery in the front end? Any help will be very much appreciated. I need the systemFeedBack to be sent when I redirect Mysql::runAdhocQuery($insert_sql, $link); echo MyClass::systemFeedBack(202, "Registration successful", "User can Log in"); header("Location: http://localhost/myProject/#/");

Upvotes: 0

Views: 57

Answers (1)

Sharan Mohandas
Sharan Mohandas

Reputation: 871

Since you would be passing the variables via url you can either get the variables using Jquery or Javascript. Below is a pure JavaScript code to GET the query params.

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

// query string: ?foo=lorem&bar=&baz
var foo = getParameterByName('foo'); // "lorem"
var bar = getParameterByName('bar'); // "" (present with empty value)
var baz = getParameterByName('baz'); // "" (present with no value)
var qux = getParameterByName('qux'); // null (absent)

Credits : How can I get query string values in JavaScript?

Upvotes: 2

Related Questions