本文介绍了我应该添加AJAX逻辑的到我的PHP类/脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始做一个PHP / AJAX的网站,我想知道,我要补充的功能为只包含内容

I just started making a PHP/AJAX site and I was wondering where I should add the functionality to "only include the content".

我应该有,如果在我的检查一个ContentOnly获取参数的页眉和页脚的脚本语句?然后追加该参数的查询字符串在我的AJAX调用?

Should I have if statements in my header and footer scripts that check for a "ContentOnly" get parameter? And then append that parameter to the query strings in my AJAX calls?

或者我应该用在AJAX侧的过滤器,只抢到的主要内容股利。就像在jQuery的:

Or should I use a filter on the AJAX side to only grab the main content Div. Like in jquery:

$(this).load("/myPhpPage.php #mainContentDiv")

第一种方法会更快吧?但第二种方法将保持在presentation端AJAX功能,进出的OG我的PHP。

The first method would be faster right?But the second method would keep the AJAX functionality on the presentation side, and out og my PHP.

还是有第三种方法?我想保持我的PHP脚本完好,因此,如果奥尤直接​​去给他们,页眉和页脚都在那里。在此先感谢!

Or is there a third method? I want to keep my PHP scripts intact, so that if oyu go to them directly, the header and footer are there. Thanks in advance!

推荐答案

请不要使用AJAX是为了使用AJAX的。

Please don't use AJAX for the sake of using AJAX.

这是说,大多数AJAX库传递 X-要求 - 以 HTTP表明它是一个Ajax请求头。您可以使用头,以决定是否要包括页眉/页脚等。

That said, most AJAX libraries pass a X-Requested-With HTTP header indicating that it's an AJAX request. You can use that header to decide whether to include your header/footer etc.

这篇关于我应该添加AJAX逻辑的到我的PHP类/脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 23:41