开发者

Ajaxify PHP application

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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜