douwen3965 2010-07-11 15:14 采纳率: 0%
浏览 18

世界上最奇怪的错误(PHP $ _GET,$ _POST,$ _REQUEST和ajax)

I hope you'll able to help me. I'm fed up of trying things without any solution and php it's just driving me crazy. I'm looking for help because I have a html document where I use ajax thanks to jquery api. Inside this file, in a js function I have:

$.ajax({ type: "GET", url: "c.php", data: "dia="+matriz[0]+"&mes="+matriz[1]+"&ano="+matriz[2]+"&diaa="+matriz2[0]+"&mess="+matriz2[1]+"&anoo="+matriz2[2]+"&modo=0&semana=0", success: Mundo, error: function(e){ alert('Error: ' + e); } });

This code allows me to send the information that I want to the file c.php where I have:

include('funciones.php'); include('config.php');

 $mierda = array();
 $mierda[0] = $_GET['modo']; 
 $mierda[1] = $_GET['dia']; 
 $mierda[2] = $_GET['mes']; 
 $mierda[3] = $_GET['ano']; 
 $mierda[4] = $_GET['diaa']; 
 $mierda[5] = $_GET['mess']; 
 $mierda[6] = $_GET['anoo']; 
 $mierda[7] = $_GET['semana'];   

As you see it's very simple. My crazy problem is that with firebug I've seen that the data is sent well but for some reason I can't use it. I have tried with $_Get, $_post and $_request and always is the same problem. But this can be stranger... If I put:

echo json_encode($mierda);

then miraculously, the php returns the data that I have passed so in conclusion I have:

  1. I can send the data to the php file well
  2. I can print all the data that I have sent well just accessing yo $_GET, $_POST, $_REQUEST
  3. I can't use any value separatly like $_GET['dia']

What's going wrong there?

PS. The include php files are functions that access to my database so there's no interaction with them.

  • 写回答

4条回答 默认 最新

  • 我在西湖1 2010-07-11 15:19
    关注

    If you are returning a json value use json to read that.

    See http://api.jquery.com/jQuery.getJSON/

    http://pinoytech.org/blog/post/How-to-Use-JSON-with-jQuery-AJAX

    Here is an example to read json value

    $('document').ready(function(){
        $('#submit).click(function(){
            $.post('your_php_page.php', {employee_id: '456'},
                function(data){
                    console.log(data.first_name);
                    console.log(data.last_name);
                }, 'json');
        })
    });
    

    Hope it helps

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么