如何使用jQuery获取URL参数?

时间:2022-09-20 10:28:11

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请求,并希望用它发送URL变量的数据。我尝试过使用PHP的GET,但是没有发送。

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

3 个解决方案

#1


4  

you need to echo the get variable.

你需要回显get变量。

$.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());
       }
})

#2


3  

There are two things.

有两件事。

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

First is <?php echo $_GET['name']; ?>.

首先是 。

Second is missing closing bracket $("#div").html(data());

第二个是缺少结束括号$(“#div”)。html(data());

Hope this will help you.

希望这会帮助你。

#3


1  

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

#1


4  

you need to echo the get variable.

你需要回显get变量。

$.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());
       }
})

#2


3  

There are two things.

有两件事。

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

First is <?php echo $_GET['name']; ?>.

首先是 。

Second is missing closing bracket $("#div").html(data());

第二个是缺少结束括号$(“#div”)。html(data());

Hope this will help you.

希望这会帮助你。

#3


1  

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