Trying to use a simple AJAX call, where I can pass a variable around and display in the modal. That side works, however I cant retrieve the variable from the GET.
The following echo var_dump($_GET);
->
array(2) { ["VALUE I WANT"]=> string(0) "" ["_"]=> string(13) "1431441301242" }
However, $TempName = $_GET['Name'];
returns no value?
AJAX:
$('#exampleModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('whatever') // Extract info from data-* attributes
var modal = $(this);
var dataString = recipient;
$.ajax({
type: "GET",
url: "/getEventDetails.php/",
data: dataString,
cache: false,
success: function (data) {
console.log(data);
console.log(dataString);
console.log(recipient);
$('.dash').html(data);
},
error: function(err) {
console.log(err);
}
});
})
You haven't assigned a name to your value in JS. PHP REQUIRES form submissions be in key=value
format so it can built the _GET/_POST arrays. Since you haven't provided a name, there's no key for PHP to build the array with - no key, no value.
Try
data: {"foo":dataString}
then $_POST['foo']
.
Alternatively, if you're sending over only a single value, then you can do
$value = file_get_contents('php://input');
to read the raw post data.
$('#exampleModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var recipient = button.data('whatever') // Extract info from data-* attributes
var modal = $(this);
var dataString = recipient;
$.ajax({
type: "GET",
url: "/getEventDetails.php/",
data: {
recipient: recipient
},
cache: false,
success: function (data) {
console.log(data);
console.log(dataString);
console.log(recipient);
$('.dash').html(data);
},
error: function(err) {
console.log(err);
}
});
And in PHP you will get it as
$recipient = $_GET['recipient'];