weixin_33725722 2018-01-31 07:50 采纳率: 0%
浏览 16

未获得AJAX响应

I am working on page where I am sending AJAX request on click of radio button. Three radios are there to list out users which are 'Unapproved', 'Approved' and 'All'. Based on the radio selection I want to show there respective data in a table. Currently I am not getting the response from the requested page in AJAX function. I will be highly thankful and appreciating any help. My code,

    <script>
        $('#selection').change
        (

            function() 
            {
              var selected_value = $("input[name='users']:checked").val();
              //till here the code works fine.
$.ajax
                ( 
                    {
                        url: "approval_ajax.php",
                        dataType : "json",
                        type: "POST",
                        cache: false,
                        data: { selected_value : selected_value },

                        success: function(response)
                        {
                             console.log(response);
                                var len = response.length;
                           for(var i=0; i<len; i++){
                                 var id = response[i].id;
                                 var email = response[i].email;
                                 var employee_id = response[i].employee_id;
                                 var first_name = response[i].first_name;
                                 var middle_name = response[i].middle_name;
                                 var last_name = response[i].last_name;
                                 var mobile = response[i].mobile;
                                 var created_on = response[i].created_on;
                                 var disabled = response[i].disabled;

                    var tr_str = "<tr>" +
                        "<td>" + (i+1) + "</td>" +
                        "<td>" + email + "</td>" +
                        "<td>" + employee_id + "</td>" +
                        "<td>" + first_name + "&nbsp;" + middle_name + "&nbsp;" + last_name + "</td>" +
                        "<td>" + mobile + "</td>" +
                        "<td>" + created_on + "</td>" +
                        "<td><input type='checkbox' name='check[]'"  + disabled +  "value= '"  + id +  "' class='checkbox' id='select_all' ></td>" +
                          "<input type='hidden' value='"  + id +  "' name='user_id' id='user_id' >" +
                        "</tr>";

                    $("#example").append(tr_str);
                }
                           alert("AJAX was a success");
                        }
                    }
                );
            }
        );
    </script>

And now my approval_ajax.php

   <?php


session_start();

require("../includes/config.php"); 
require("../classes/Database.class.php"); 
$db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);  

$return_arr = array();
$status=''; 

   if($_SERVER['REQUEST_METHOD'] == 'POST')
   {
       $value = filter_input(INPUT_POST, "selected_value");


       if (isset($value))
       {
         $users=$value;

}else{
    $users='';
}

switch ($users)

{

case "all":
  $sqlQuery = "SELECT * FROM tbl_user WHERE type =3";       

break;

case "approved":
  $sqlQuery = "SELECT * FROM tbl_user WHERE type =3 AND status =1";   
break;

case "unapproved":
  $sqlQuery = "SELECT * FROM tbl_user WHERE type =3 AND status =0";   

break;

}

$sq = $db->query($sqlQuery);


if ($db->affected_rows > 0) {

while ($row = mysql_fetch_array($sq)) {
    $disabled = '';
    if ($status == '1') {

        $disabled = "disabled = 'disabled' checked='checked' ";
    }

    $id = $row['id'];
    $email = $row['email'];
    $employee_id = $row['employee_id'];
    $first_name = $row['first_name'];
    $middle_name = $row['middle_name'];
    $last_name = $row['last_name'];
    $mobile = $row['mobile'];
    $created_on1 = $row['created_on'];
    $created_on = date("d-m-Y", strtotime($created_on1));

    $return_arr[] = array("id" => $id,
    "email" => $email,
    "employee_id" => $employee_id,
    "first_name" => $first_name,
    "middle_name" => $middle_name,
    "last_name" => $last_name,
    "mobile" => $mobile,
    "created_on" => $created_on
    "disabled" => $disabled
    );
}
}
header('Content-Type: application/json', true, 200);
echo json_encode($return_arr);

}

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题
      • ¥15 gem5搭建arm v8
      • ¥15 安卓时间管理APP,怎么做
      • ¥15 这段有什么bug 为什么总报错
      • ¥15 Intel Realsense深度相机(D415/D435)拍摄梯子获取梯子点云