为了账号安全,请及时绑定邮箱和手机立即绑定

PHP _GET 不随 URL 动态更新

PHP _GET 不随 URL 动态更新

PHP
德玛西亚99 2023-03-04 17:42:25
我正在尝试使用 _GET 方法动态获取查询参数。我的功能看起来像这样:var baseURL = "http://example.org";// clears the last query paramshistory.pushState("", document.title, baseURL);// retrieves the value from the HTML codevar value = document.getElementById('id').value;// URL with updated query paramsvar updatedURL = document.URL + "?value=" + value;// pushing the new URL without refreshing the page.history.pushState("", document.title, updatedURL);// URL looks something like this "http://example.org?value=1"但是当我尝试使用_GET['value']从 URL 检索值时,它只获取页面初始化的值并且不会动态更新,有没有什么方法可以在不刷新页面的情况下检索这个值?
查看完整描述

1 回答

?
森林海

TA贡献2011条经验 获得超2个赞

history.pushState()只需更改浏览器 URL 的值。它实际上并不发出服务器请求并加载 _GET 变量。这就是您无法访问它们的原因。


要在不刷新页面的情况下执行此操作,您需要进行 ajax 调用。


$.ajax({

  type: "GET",

  url: "yourpage.php",

  data: {value:value},

  cache: false,

  success: function(result){

     // do something with the returned data

  }

});


查看完整回答
反对 回复 2023-03-04
  • 1 回答
  • 0 关注
  • 130 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号