Reputation: 582
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
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