weixin_33736832 2016-02-20 13:13 采纳率: 0%
浏览 84

AJAX响应为空

I've tried this like 8 hours and I don't get it.

With $.ajax I get datas from my database via PHP-script. But in this case it doesn't seem to work and I don't no why. The data2 is empty, no matter what.

$.ajax({
  url: 'http://myurl.de/get', 
  data: [{ 'person_id': 2, 'action': 'getLinks' }],
  method: 'POST',
  success: function(data2){
    console.log(data2);
  }
});

The PHP-script (important parts) looks like this

function getLinks($person_id)
{
    /* sql here */  

    /* format sql-output here */

    return $output;
}

if($_POST['action'] == 'getLinks'){
    echo getLinks($_POST['person_id']);
}

The funny thing is, I have the exact AJAX-request in the JavaScript-file some lines above with another action and it works perfectly. When I try to get the data directly in the PHP-file I get the result. The return $output is always with the data, but in don't comes to the JavaScript file.

The AJAX always calls the success-function, but with no data2.

  • 写回答

3条回答 默认 最新

  • ℙℕℤℝ 2016-02-20 13:17
    关注

    Try using only object as data, without wrapping it in an array:

    $.ajax({
      url: 'http://myurl.de/get', 
      data: { 'person_id': 2, 'action': 'getLinks' },
      method: 'POST',
      success: function(data2){
        console.log(data2);
      }
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容