AJAX后自行在PHPAJAX、PHP

由网友(顺⒎自然″)分享简介:我觉得这是一件我应该学会了现在,我敢肯定,这是小东西,我失踪,但我可以用澄清,以确保我的做法是正确的。I feel like this is something that I should have learned by now, and I'm sure it's something small I'm missi...

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

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.

阅读全文

相关推荐

最新文章