尝试检索DATA时,AJAX在实时服务器上不起作用。但是当我尝试发送数据时它工作正常

时间:2019-12-07 08:00:14

标签: javascript php mysql json ajax

我对此问题有些困惑,因为到本地服务器的所有ADD和RETRIEVE数据都运行良好。但是不在实时服务器上。

下面是我的代码:

AJAX:

function baseUrlAction(){
     return location.protocol + "//" + location.host + "/json/ajax/ajax_controller.php";
}

function Modal_value_display($id_value){

            var id = $id_value;

            $.ajax({
                type : 'POST',
                url : baseUrlAction() + '?btn=process_get_projects_value',
                context : this,
                dataType : 'json',
                data : {
                    project_id : id
                },
                error : function(ts){
                    console.log(ts.responseText);
                },
                success : function(data){

                    var row = "";

                    if(jQuery.isEmptyObject(data)){


                    }else{

                        $.each(data, function(key,value){

                            var prev_val = value.pro_img_id;

                            var arr = prev_val.split(",");
                            for(var x=0;x<arr.length;x++){
                               if(x == 0){
                                    row += '<div class="item active">';
                                    row += '<img src="img/project_img/'+arr[x]+'.jpg">';
                                    row += '</div>';
                               }else{
                                    row += '<div class="item">';
                                    row += '<img src="img/project_img/'+arr[x]+'.jpg">';
                                    row += '</div>';
                               }

                            }

                            $('#item_gallery').html(row).fadeIn('slow').slideDown('slow');

                            document.getElementById("Project_name").innerHTML = value.pro_name;
                            document.getElementById("Project_description").innerHTML = value.pro_description;
                            document.getElementById("placeholder_code").href = value.pro_code;
                            document.getElementById("placeholder_site").href = value.pro_website;

                        });


                        slider_next_back();

                    }


                }
            });

        }

在这种情况下,我需要显示来自服务器的动态模式值。这就是为什么我使用AJAX方法实现目标的原因。但是不幸的是,当我尝试使用实时服务器时,它不起作用。我不确定我是否以正确的方式使用了该方法,这将是控制台显示中的错误,这很难弄清楚。

  

无法加载资源:服务器的状态为500()

AJAX控制器:

<?php

class Json_Controller{

    public function __construct(){

        $button=null;

        if(isset($_GET['btn'])){           
           $button = $_GET['btn'];         
        }

        switch($button){    

            case 'process_get_projects_value':
                $this->process_get_projects_value();
                break;  
        }
    }


    public function process_get_projects_value(){

        include 'ajax_model.php';

        $arr = array();
        $error = false;

        $data['result_project'] = $model->process_get_projects_value($_POST);

        if($data['result_project']){
            foreach($data['result_project'] as $row){
                $arr[] = array('pro_img_id'=>$row['pro_img_id'],
                                'pro_name'=>$row['pro_name'],
                                'pro_description'=>$row['pro_description'],
                                'pro_code'=>$row['pro_code'],
                                'pro_website'=>$row['pro_website']);
            }
        }

        echo json_encode($arr);
    }


 }

$contros = new Json_Controller();

?>

AJAX模型

<?php
class Json_Model{
    var $con;
    var $logged;
    var $dbhost;
    var $dbuser;
    var $dbpass;
    var $dbname;

    function __construct() {

        $this->dbhost = 'localhost';
        $this->dbuser = '******';
        $this->dbpass = '******';
        $this->dbname = '******';  
        $this->InitDB();
    }
    function InitDB(){
        $this->con = mysqli_connect($this->dbhost, $this->dbuser, $this->dbpass)  or die(mysqli_error($this->con));
        mysqli_select_db($this->con, $this->dbname) or die(mysqli_error($this->con));  

        session_start();  
    }
    function query($query){
        return mysqli_query($this->con,$query);
    }
    function free_result($query){
        return mysqli_free_result($query);
    }
    function num_rows($query){
        return mysqli_num_rows($query);
    }
    function fetch_data($query){
        return mysqli_fetch_assoc($query);
    }



        public function process_get_projects_value($post){

            $data="";

            $query = $this->query('SELECT * FROM projects_tbl where pro_id = "'.$post['project_id'].'" and status = 1  ');

            if($this->num_rows($query)>0){
                while($yu = $this->fetch_data($query)){
                    $data[] = $yu;
                }
                return $data;
            }else{
                return FALSE;
            }
        }

}


$model = new json_model();

?>

我要花两(2)天的时间来解决此问题,因为我找不到解决方案。 :(任何人都可以帮助我吗?

0 个答案:

没有答案