jord49
jord49

Reputation: 582

Is it possible to send a value to php file whilst performing a jquery GET request

I am making a GET request in jQuery to a PHP file and need to send a variable to the PHP for use in the query. Is this possible? I want to grab the emailAddress variable in the php.

 function getData(){

    var emailAddress = "[email protected]";

    $.getJSON('myfile.php', function(data){             
    $.each(data, function(key, val) {
    $("#userAge").val(val.age);     
                                          });
            });
 }

So in the PHP i want to be able to select all that have the email address that I have passed in.

I have to use jQuery and PHP as i am developing a hybrid app in PhoneGap that cant use PHP directly.

Thanks.

Upvotes: 1

Views: 27

Answers (1)

Barmar
Barmar

Reputation: 781300

The optional second argument is used for passing parameters:

$.getJSON('myfile.php', { email: emailAddress }, function(data) {
    $.each(data, function(key, val) {
        $("#userAge").val(val.age);
    })
});

In the PHP script use $_GET['email'] to get the email address.

Upvotes: 3

Related Questions