所有AJAX调用仅包含一次PHP文件 [英] Include the PHP file only once for all AJAX Calls

查看:69
本文介绍了所有AJAX调用仅包含一次PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在3个不同的按钮单击上使用ajax在页面index.php上包含了3个不同的PHP文件,但是所有这些PHP文件还需要另一个PHP文件,比如a.php

I am including 3 different PHP files on a page index.php using ajax on 3 different button clicks, but all these PHP files further requires another PHP file, lets say it a.php

所以在这种情况下,我在用ajax调用的所有三个文件中都包含了a.php

So in this case I've included a.php in all three files I'm calling with ajax

我认为在所有三个文件中都包含a.php并不是正确的方法

Including a.php in all three files is not the right way to do it, I think

我怎样才能使a.php仅包含一次,以便它与所有这三个都兼容?

How can I make a.php included only once so that it works with all three?

推荐答案

如果我误会了,抱歉-您有类似的东西:

Apologies if I'm misunderstanding - You have something like:

Ajax调用1:file1.php-输出对页面的响应

Ajax call 1: file1.php - output response to page

Ajax调用2:file2.php-输出对页面的响应

Ajax call 2: file2.php - output response to page

Ajax调用3:file3.php-输出对页面的响应

Ajax call 3: file3.php - output response to page

所有这3个文件都需要a.php中的功能才能运行,对吗?

All 3 of those files need the functionality in a.php to run, correct?

您是否可以将3个文件组合为1个PHP文件(包括a.php),然后将每次单击按钮所特有的参数传递给它们?因此,您将拥有:

Could you instead combine the 3 files into 1 PHP file, with a.php included, and then pass them whatever parameters are specific to each button click? So you'd have:

Ajax调用1:bigfile.php?parameter_blah = a

Ajax call 1: bigfile.php?parameter_blah=a

Ajax调用2:bigfile.php?parameter_blah = b

Ajax call 2: bigfile.php?parameter_blah=b

Ajax调用3:bigfile.php?parameter_blah = c

Ajax call 3: bigfile.php?parameter_blah=c

再次,如果我误解了,我们深表歉意.

Again, apologies if I've misunderstood.

这篇关于所有AJAX调用仅包含一次PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆