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 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献