duanbi5906 2012-06-04 15:55
浏览 56
已采纳

无需重新加载页面即可更新Postgres数据库

I'm essentially building a personal reddit for fun and experience (I'm pretty new to this whole thing). 

On other web things I've made where changes must be applied to the same page, I used a form, where the action would point to the current page. In PHP, I would have a function that would check for the POST variables from that form, then make the database query before the page loads. This way, when the function later on is called to display the data, it would have the new stuff added. 

This has worked tremendously well and happens instantaneously because my sites are exclusively deployed to local networks. I came up with it on my own (I realize it may not be totally efficient). Before, I would have it go to a different page to process with a back button. 

On my current project, when I click a voting button, the same thing happens and it works fine. However, this page is much longer than anything I've made previously, and as a result, it jumps to the top of the page. It's a jarring experience. I'd like to keep everything inline, like nothing happened. 

What kinds of tricks that require little (read: simple) to no server modification can I use? 

  • 写回答

2条回答 默认 最新

  • dqvj51875 2012-06-04 15:58
    关注

    to make your href stop reloading the page add this to your hrefs:

     <a href="#" onclick="return false">blah</a>
    

    if you are using buttons to pass POST data from forms to your PHP, the same onclick trick wil work. but I would suggest you take a quick google for "jQuery AJAX"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • douyi7055 2012-06-04 16:06
    关注

    If you want to apply old tech use AJAX http://www.w3schools.com/ajax/default.asp.

    If you want to use new tech , html 5 , try websockets http://en.wikipedia.org/wiki/WebSocket

    or server sent events http://en.wikipedia.org/wiki/Server-sent_events .

    Links are for basic knowledge , you'll have to search more for in depth research .

    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 spyder运行重复
  • ¥15 有偿做一个PUBG识别枪械配合罗技宏的
  • ¥15 我考考你,这代码是对的还是错的?
  • ¥15 我用C语言easyx图形库绘制了一个3d游戏方框透视,但进入游戏时候鼠标准星对准方框边缘 鼠标光标就会弹出来这是啥情况怎样让光标对准绘制的方框点击鼠标不弹出光标好烦这样
  • ¥20 用Power Query整合的问题
  • ¥20 基于python进行多背包问题的多值编码
  • ¥15 相同型号电脑与配置,发现主板有一台貌似缺少了好多元器件似的,会影响稳定性和使用寿命吗?
  • ¥15 C语言:数据子序列基础版
  • ¥20 powerbulider 导入excel文件,显示不完整
  • ¥15 paddle训练自己的数据loss降不下去