weixin_33701617 2017-01-07 23:05 采纳率: 0%
浏览 180

AJAX返回空值

I'm trying to get my AJAX request to PHP working. It should, after sending the AJAX request loop through some items and then send back an array of data. The problem is that it returns an empty string.

Here's the code:

PHP

if(isset($_POST['action']) && !empty($_POST['action'])) {

    $available = array();

    for($i = 0; $i <= 50; $i++) {

        $gt = substr(md5(microtime()),rand(0,26),3);

        $check_url = "SOMEURL" . $gt . ".card";
        $check_url_source = file_get_contents( $check_url );

        $exists = ( preg_match( "#<div id=\"Gamerscore\">--</div>#i", $check_url_source ) ) ? false : true;

        if($exists == false) {
            array_push($available, $gt);
        }
    }

    echo json_encode($available, JSON_FORCE_OBJECT);
}

JQuery

$('document').ready(function() {
    $.ajax({
        url: '/GamertagChecker/helpers/magic.php',
        data: {action: 'load'},
        type: 'post',
        success: function(output) {
            console.log(output);
        },
        error: function(jqXHR, exception){
            console.log("Error: " + jqXHR.responseText);
        }
    });
});
  • 写回答

1条回答 默认 最新

  • weixin_33744854 2017-01-08 01:24
    关注

    After looking through a lot of solutions and research by others here I've finally found the problem.

    Because I was using the PHPStorm IDE, I was also using the build-in server. Unfortunately there is a bug in the server which causes $_POST to not work.

    After copying the files to a different IDE I finally got it working. Thanks to everyone who tried to help, your effort is much appreciated!

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥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