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.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度