PHP渲染/重定向AJAX调用重定向、PHP、AJAX

2023-09-10 14:46:18 作者:Addictive丶(着迷)

我工作的一个PHP应用程序和失踪的一些Rails所具有的功能。我现在有一个AJAX表单提交的时候访问my_page_save_ajax.php。当我处理表单和保存它,我想重定向AJAX调用要么my_page_show_ajax.php如果成功或回my_page_edit_ajax.php是否发生错误。

I am working on a PHP application and missing some of the functionality that Rails has. I currently have an AJAX form that when submitted accesses my_page_save_ajax.php. After I process the form and save it, I would like to redirect the AJAX call to either my_page_show_ajax.php if successful or back to my_page_edit_ajax.php if an error occurred.

我曾想过使用包括my_page _..._ ajax.php ,但我一直有问题的文件路径和PHP不知道呈现了什么。更何况,这两个文件包括utilities.php 我怕,就会产生冲突。我想我可以使用 include_once 但似乎有可能是一个更好的解决方案。

I have thought about using an include my_page_..._ajax.php, but I have always had problems with the file paths and PHP not knowing what to render. Not to mention, both of those files include utilities.php and I'm afraid there might be conflicts. I guess I could use include_once but it seems like there might be a more elegant solution.

我怎么可以处理的形式和返回另一个PHP页面的输出?

How can I process the form and return the output of another PHP page?

非常感谢!

推荐答案

如果您重定向Ajax响应,它实际上不会重定向用户的浏览器的任何地方。这只会影响到数据来源是什么回通过AJAX调用。这可能是一个很好的实例,简单地不使用AJAX,因为它听起来像,用户可以继续仅一个的两个路径​​。

If you redirect the AJAX response, it won't actually redirect the user's browser anywhere. It will simply affect what data comes back through the AJAX call. This may be a good instance to simply not use AJAX, since it sounds like the user may go on only one of two paths.

如果您仍然希望将用户重定向,您可以发送回一个JavaScript片段,它通过设置window.location将用户重定向

If you still want to redirect the user, you could send back a javascript snippet which redirects the user via setting window.location

 
精彩推荐