helloxielan 2015-04-10 05:03 采纳率: 0%
浏览 51

AJAX:$ _GET不返回任何值

Been trying to figure this out for hours...

I am attempting to use AJAX by grabbing values from a jQuery slider I have contained in an <input> tag. AJAX does not fail (see code), and when I console.log the variable I am trying to send through Data:, it prints out correctly.

note: The jQuery and php are on the same page, so no url: parameter, or whatever you will call it is used.

Here is the <script> portion:

   jQuery(function($){
        $("input[id='protein-slider']").ready(function(){
            var p_range;
            var request;
            $("input[id='protein-slider']").each(function () {
            p_range = $(this).val();
            });
            console.log(p_range) //Returns correct values

            request = $.ajax({
                type: "POST",
                data: p_range,
            });  
            request.done(function (response, textStatus, jqXHR){
                console.log("Hooray, it worked!"); //This prints, no error
            });
            request.fail(function (jqXHR, textStatus, errorThrown){
                console.error(
                    "The following error occurred: "+
                    textStatus, errorThrown
                );
            });
        });
    });

and the <?php ?> code in correlation with this function is:

                echo $_SERVER['QUERY_STRING']; //returns nothing
                $income_data = $_GET['p_range']; 
                echo $income_data; //returns nothing
                var_dump($income_data); //returns "NULL"

I've lost track of all of the other methods I have done and the other countless awnsers I have read on here. None seem to work and it's getting quite depressing...

Hopefully one of you guys can spot something that I am doing stupid...

Thanks!

  • 写回答

2条回答 默认 最新

  • weixin_33704234 2015-04-10 05:06
    关注

    Your ajax is for POST, change it to GET

    request = $.ajax({
        type: "POST",
        data: p_range,
    }); 
    

    or you access your params in php as

    $var = $_POST['p_range'];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?
  • ¥15 Java+vue部署版本反编译
  • ¥100 对反编译和ai熟悉的开发者。
  • ¥15 带序列特征的多输出预测模型