Ajaxify PHP 应用程序

发布于 2024-11-05 05:34:31 字数 605 浏览 2 评论 0原文

是否有任何 javascript 插件/库/脚本可以将标准 PHP 转换为使用 ajax 调用而不是标准链接。

理想情况下,这将是位于现有应用程序之上的东西,并允许应用程序在禁用 javascript 时正常使用,但在 javascript 可用时使用 ajax。

它还需要允许普通的 javascript 插件(例如 jeditable、jquery-ui 拖放等)无需修改即可工作。

我确实尝试了下面的代码,但是一旦页面加载,页面上已加载的 JavaScript 插件就无法工作,而且这只适用于一个链接,然后浏览器又回到使用标准请求。

$('a').bind('click',function(event){
            event.preventDefault();
            $.get(this.href,{},function(response){ 
               $('#response').html(response);
            })  ;
         });

另外,当页面使用 ajax 调用而不是正常链接时,是否可以拦截浏览器的后退/前进按钮以正常工作。

我知道我在问...谢谢

Is there any javascript plugin/library/script that will can transform a standard PHP to use ajax calls instead of standard links.

Ideally this would be something that sits on top of the existing application and allows the application to work using as normal when javascript is disabled but uses ajax when javascript is available.

It also needs to allow normal javascript plugins e.g. jeditable, jquery-ui drag n drop etc..., to work without modifications.

I did try the code below but the javascript plugins that where already loaded on the page failed to work once the page had loaded and also this only worked for one link and then the browser went back to using standard requests.

$('a').bind('click',function(event){
            event.preventDefault();
            $.get(this.href,{},function(response){ 
               $('#response').html(response);
            })  ;
         });

Also, is there anyway to intercept the back/forward button of the browser to work correctly when the page uses ajax calls instead of the normal links.

I know I am asking... thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫轩蝶泪 2024-11-12 05:34:32

Xajax 项目 是让 PHP 与 Ajax 一起工作的一个很好的尝试。通过一些哄骗,您可以使用 Xajax 异步调用 PHP 函数。它运行高效,我的公司已在几个站点上投入生产。虽然我个人更喜欢 JQuery 的 ajax,但这对于后端人员来说更容易理解。

话虽这么说,文档很少,该项目几乎从不更新,而且大多数论坛都是母语不是英语的人经常光顾的。因此,答案(如果有的话)通常很难理解。但是,如果您是一位有能力的 PHP 开发人员并且至少熟悉 Javascript 概念,那么您应该能够在一个小时内掌握它。

The Xajax project is a good attempt to make PHP work with Ajax. With a bit of cajoling, you can use Xajax to call PHP functions asynchronously. It works efficiently and my company has it in production on a couple of sites. While I personally prefer JQuery's ajax, this has been much easier for the back-end guys to figure out.

That being said, documentation is sparse, the project is almost never updated, and most of the forum is frequented by people who don't speak English natively. So, answers (if they come) are often very difficult to understand. However, if you're a competent PHP developer and are at least comfortable with Javascript concepts, you should be able to pick this up in under an hour.

卷耳 2024-11-12 05:34:31

我知道的最好的事情是 https://github.com/browserstate/History.js/

$('a').live('click',function(event){
            event.preventDefault();
            $.get(this.href,{},function(response){ 
               $('#response').html(response);
            })  ;
         });

如果您希望事件在动态加载的内容上工作,您也应该使用

The best thing i know of is https://github.com/browserstate/History.js/ , also you should use

$('a').live('click',function(event){
            event.preventDefault();
            $.get(this.href,{},function(response){ 
               $('#response').html(response);
            })  ;
         });

if you want your events to work on dynamically loaded content

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文