Didn"t forge 2017-06-27 13:18 采纳率: 25%
浏览 17

在AJAX中使用内联PHP [重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming" dir="ltr">What is the difference between client-side and server-side programming?</a>
                            <span class="question-originals-answer-count">
                                (4 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2017-06-27 13:25:06Z" class="relativetime">2 years ago</span>.</div>
        </div>
    </aside>

I need to call a couple small PHP functions that should execute after the user makes changes in the DOM. I know this can be done by capturing the change in jquery, then pointing an ajax call to a separate script with the function inside it; but having a few of these small functions I would rather not make a file for each, if possible. As such, is there a way to include the PHP code directly within the ajax call and not go to a separate url?

EDIT 1

Assuming a post request is being made, something like the following is what I'd like to do:

$("select").change(function() {
    $.post("<?php ... ?>", {option: $(this).val()}, function(return) {
        //do stuff with results
    }
});
</div>
  • 写回答

1条回答 默认 最新

  • elliott.david 2017-06-27 13:22
    关注

    With ajax you can call a php file on the server but not on client side. If you want to run php code directly on client side, you'd need to install php on each client which, I really don't recommend.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog