0

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/#/");

4
  • what you tried? any code? Commented Feb 18, 2016 at 9:01
  • Yeah, I tried echoing and returning. Afterewards using the Header(); but nothing Commented Feb 18, 2016 at 9:03
  • Please post your code then...done Commented Feb 18, 2016 at 9:03
  • cool lemme put it up Commented Feb 18, 2016 at 9:11

1 Answer 1

2

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?

Sign up to request clarification or add additional context in comments.

2 Comments

my problem is with the PHP side. Sorry if I wasnt clear
glad it helped you :)

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.