douguyi3903 2013-01-22 19:25
浏览 11
已采纳

获取一个URL并添加/?var0 = val0&var1 = val1而不离开页面而没有用户输入

OK - Thanks for taking the time!

I am using WP on a CentOS 6 server. I have a plug in with the functions, I have a function that makes a DB call and populates relevant products based on $_GET variables, I took from one of the other project and modify it so it works! But here where I run in to the problem, I go to the main page and i have a function that gets called first, goes through the URL name and determines the categories id and then from that I need to pass that to the URL so that when the next function then calls $_GET["category_id"] and that ID is there and ready to be use and it it does its magic. (all staying on the same page no refreshing or anything)

So I need to put that on the URL as the page is being loaded and so that I can use it (Again i get the variables from a function that is doing all the work with the address for relevant info,) So how do i do it? HTML or PHP, and a straight forward way no extra installs would be nice :)

Edit 1: So is there something then I could integrate in that would be simple and straight forward that would allow me to do a mini refresh and get the right variables in place, never used JavaScript but seams to be getting or something in php ... Ideas are welcome :)

  • 写回答

2条回答 默认 最新

  • dongshan6870 2013-01-22 19:30
    关注

    You can with javascript and the history API

    The only way you can change the url without actually redirecting the user is by using the pushState method.

    e.g. open a console and copy and paste this:

    var stateObj = { foo: "bar" };
    history.pushState(stateObj, "changes url to stackoverflow.com/yes-you-can", "/yes-you-can");
    

    You won't be redirected, and the url of your browser will change unless, basically, you're using IE 9 or less. You can see a demo of this on html5demos.com

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题