简体   繁体   English

Ajax在同一函数中调用多个php文件

[英]Ajax calling multiple php files in same function

So, few days ago I asked this question Session data displaying url of previous picture 所以,几天前我问了这个问题会话数据显示上一张图片的网址

It is working, but is there any way to call multiple things at same time? 它正在工作,但是有什么办法可以同时调用多个东西?

I have counter.php and report.php, they are both accessing session data from getRandom.php. 我有counter.php和report.php,它们都从getRandom.php访问会话数据。

function Refresh()
{
$('#picturehere').load('getRandom.php', function(){$load('report.php');});
};

My Refresh() code. 我的Refresh()代码。 I want to display counter.php in its own div, is this possible to do? 我想在自己的div中显示counter.php,这可能吗?

When I try to separate my counter.php in its own line like this its getting wrong session data, from previous picture. 当我尝试像这样将自己的counter.php分隔开来时,它的会话数据与上一张图片不符。

function Refresh()
{
$('#picturehere').load('getRandom.php', function(){$load('report.php');});
$('#counter').load('counter.php');
};

Thanks. 谢谢。

There is no need to make 3 different http requests / ajax calls to get information from the same server. 无需进行3个不同的http请求/ ajax调用即可从同一服务器获取信息。

You should make one ajax call and combine the scripts on the server side or have one script that includes the other scripts. 您应该进行一个ajax调用,并在服务器端组合脚本,或者拥有一个包含其他脚本的脚本。 Then you can combine the output data in an array or object and json_encode() it to send it back to the browser. 然后,您可以将输出数据组合到一个数组或对象中,并对其进行json_encode()将其发送回浏览器。 There you can get the different parts and put them in different html elements as desired. 在那里,您可以获取不同的部分,并根据需要将它们放入不同的html元素中。

You might need to move to a bit more complete method like $.ajax() instead of just using .load() though. 您可能需要移动到更完整的方法,例如$.ajax()而不是仅使用.load()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM