The Codesee The Codesee - 29 days ago 8
PHP Question

How can I get a URL parameter with jQuery?

I am sending an AJAX request and want to send the data of the URL variable with it. I have tried using PHP's

GET
, however it is not sent.

$.ajax({
type: "POST",
url: "send.php",
data: "name=" + "<?php $_GET['name']; ?>",
success: function(data) {
$("#div").html(data);
}
})

Answer Source

you need to echo the get variable.

$.ajax({
       type: "POST",
       url: "send.php",
       data: "name=" + "<?php echo $_GET['name']; ?>", 
       success: function(data) {
           $("#div").html(data());
       }
})

moreover, its prefer you use the object to send data.

$.ajax({
       type: "POST",
       url: "send.php",
       data: {'name':'<?php echo $_GET['name']; ?>'}, 
       success: function(data) {
           $("#div").html(data());
       }
})