两个快速AJAX调用混淆PHP [英] Two rapid AJAX calls confuses PHP

查看:112
本文介绍了两个快速AJAX调用混淆PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是碰到了一些奇怪的。我有两个JSON数组其中包含不同的数据。通常我只是从其中一人需要的数据,但是当我尝试做一个双Ajax调用从两个数组中获取数据,我结束了两个电话完全相同的数据。

I just ran into something weird. I have two JSON arrays which holds different data. Usually I just need data from one of them, but when I try to do a dual ajax call to get data from both arrays, I end up with the exact same data on both calls.

说阵列1持有用户JSON数据,以及阵列2持有房屋JSON数据,我想从两个阵列获取数据:!(PS我切出的网​​址键入保存几行。)

Say array 1 holds JSON data on users, and array 2 holds JSON data on houses, and I want to get data from both arrays: (PS! I cut out the url and type to save a couple of lines.)

$.ajax({
   async:false,
   data:"type=users&id=3,5,6",
   success: function(data) {
      data = JSON.parse(data);
      alert(data.length) //will alert 3 as expected
   }
});

然后我做了第二个电话让在那里一些房屋和:

Then I make the second call to get some houses in there as well:

$.ajax({
   async:false,
   data:"type=houses&id=2,4",
   success: function(data) {
      data = JSON.parse(data);
      alert(data.length) //alerts 3 as well...
   }
});

当我看着PARAMS和响应与萤火虫,我可以看到PARAMS是正确的,但反应是错误的。

When I look at the params and response with Firebug, I can see that the params are correct, but the response is wrong.

在我的PHP我甚至想只是呼应了无坚不摧在做这个:

In my PHP I even tried to just echo out whatever comes in doing this:

echo $_GET['id'] . ", " . $_GET['type'];

这使请求看起来完全相同的两个电话......如果我把警报插图中的Ajax调用,我得到预期的结果(因为系统等待)。但我认为把他们两个是同步将足以不会崩溃了电话..?

Which made the request look the exact same on both calls... If I put an alert inbetween the ajax calls, I get the expected result (since the system waits). But I thought putting them both to be synchronous would be enough to not crash up the calls..?

编辑:我试着创造这就是所谓的AJAX功能中的PHP文件的副本,并设置呼叫转接到单独的文件,这使得一切工作正常。所以我相当肯定有什么不对的JavaScript。

edit: I've tried creating a copy of the php file which is called within the AJAX function, and setting the calls to go to seperate files, which makes everything work as expected. So I'm fairly sure there's nothing wrong with the javascript.

更多编辑:如果我删除从第二个AJAX调用的参数,我仍然得到同样的结果。看着与萤火虫的要求,我可以看到PARAMS列表是空的,但反应仍是相同的......

more edit: If I remove the parameters from the second AJAX call, I still get the same result. Looking at the request with Firebug I can see that the params list is empty, but the response is still identical...

更编辑:环顾萤火虫,我可以看到有一个叫头连接具有的价值保活,然后叫头保持活动与价值 300 。我猜这可能有一些做呢?找不到任何东西在jQuery的文档,但...

even more edit: Looking around in Firebug, I can see there is a header called connection which has the value of keep-alive, and then a header called Keep-Alive with the value of 300. I'm guessing this might have something to do with it? Can't find anything on it in the jQuery docs, though...

源$ C ​​$ C:我做了一个小测试案例,其中转载了问题:

source code: I've made a small test case, which reproduces the problem:

PHP

echo $_GET['test'];
die();

HTML

<sript>
    $(document).ready(function() {
      $.ajax({
        type:"get",
        url:"bugtest.php",
        data="test=hello",
        success: function(data) {
          $("output").append(data);
        }
      });
      $.ajax({
        type:"get",
        url:"bugtest.php",
        data="test=world!",
        success: function(data) {
          $("output").append(" "+data);
        }
      });
    });
  </script>
  <h1>AJAX bug in Aptana's PHP server?</h1>
  <output></output>

这就是我的全部,它做同样的事情!而不是得到的的Hello World 像我所料,我得到你好你好 ...

That's all I have, and it does the same thing: Instead of getting hello world! like I'd expect, I get hello hello...

推荐答案

为了确定阉PHP或JS是你可以使用这个问题的查尔斯来监视你的要求(我相信查尔斯超过萤火虫实际上,不知道为什么),并生成一个唯一的值服务器端

In order to determine wether PHP or JS is the problem you could use Charles to monitor your request (i trust charles more than firebug actually, dunno why) and generate a unique value serverside

<?php echo uniqid();

如果这两个请求返回相同的值有什么不对您的服务器,否则它的浏览器或者JS code。

If both requests return the same value there is something wrong with your server, else it's the browser or jscode.

这篇关于两个快速AJAX调用混淆PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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