Skip to content
Advertisement

How to pass variable via AJAX / jQuery?

I would like to know how do I pass a variable to another php-file via AJAX?

The variable that has to be passed is called:

JavaScript

The problem is that my form in ‘pm_form.php’ has no access to the variable ‘$id’.

My script looks like this (this script fires a modal-window and that modal window loads a form called ‘pm_form.php’):

JavaScript

When I click on a submit button of my form the variable ‘$id’ shall be passed to the appropriate php-file.

This is my form:

JavaScript

I don’t know much about jQuery / AJAX.

Solution

I just echo my $id:

href: “/includes/forms/pm_form.php?id=”, and in my pm_form.php, I can grab that id parameter using the $_GET global as:

JavaScript

Advertisement

Answer

To pass variable from one PHP page to another, you need to use POST or GET method. Use POST[‘name of tag’] and store it in a separate variable.

Eg. : $variable1 = $_POST[name];

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement