AJAX后自行在PHP [英] AJAX Post to self in PHP

查看:184
本文介绍了AJAX后自行在PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这是一件我应该学会了现在,我敢肯定,这是小东西,我失踪,但我可以用澄清,以确保我的做法是正确的。

I feel like this is something that I should have learned by now, and I'm sure it's something small I'm missing, but I could use clarification to make sure my approach is correct.

我使用AJAX来数据发布到这是一个包含PHP和HTML文件。我可以写PHP的罚款,但经过一个成功的Ajax后,我怎么只返回被通过PHP处理的数据,而不是剩余的HTML?它更好,只是张贴到一个单独的脚本?

I'm using AJAX to post data to self which is a file that contains php and html. I can write the php fine, but after a successful ajax post, how do I only return the data that is processed via php and not the remaining html? Is it better to just post to a separate script?

推荐答案

如果您有PHP处理的文件的开头POST请求,你可以做这样的事情:

If you have the PHP handling the POST request in the beginning of the file, you can just do something like this:

<?php
    if (isset($_POST['somevar'])) {
        /* do something */
        exit(0);
    }
?>

退出()将停止页面加载在该行。

exit() will stop the loading of the page at that line.

我来说,认为最好是使用一个单独的脚本来处理动态AJAX请求。

I, for one, think it's better to be utilizing a separate script to deal with dynamic AJAX requests.

这篇关于AJAX后自行在PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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