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:

            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){
                    "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...


  • 写回答

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'];
  • 游.程 2015-04-10 05:18

    Your data needs to be in key/value pair

    data: {p_range: p_range},


    $income_data = $_POST['p_range']; 



  • ¥80 关于海信电视聚好看安装应用的问题
  • ¥15 vue引入sdk后的回调问题
  • ¥15 求一个智能家居控制的代码
  • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
  • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
  • ¥20 求各位能用我能理解的话回答超级简单的一些问题
  • ¥15 yolov5双目识别输出坐标代码报错
  • ¥15 这个代码有什么语法错误
  • ¥15 给予STM32按键中断与串口通信
  • ¥15 使用QT实现can通信