dsvq5069 2019-01-16 05:16
浏览 70
已采纳

无法加载资源:PHP与jQuery回调

PHP upgrade from 5.2 to 5.6 the below code stopped working:

After Running it throwing the error: Failed to load resource: the server responded with a status of 500 (Internal Server Error). I am not sure if there is an issue with javascript or PHP itself that is causing the issue. The frontend is loading but it is not fetching the data on the callback.

Any help will be really appreciated. If this is a duplicate of some error or post, please point me towards a necessary answer. If I have done any mistake in writing the question, Please write a comment why are you doing that instead of just blatantly giving me a negative score.

Javascript snippet:

 jQuery(document).ready(function() {        
            // Get data from Outlast Server
            var url="https://xxxxx/xxxx/q_data.php?callback=?";
            jQuery.getJSON(url,  function(rts_data) {
                var deck_count = 0, shiplap_count = 0, bnb_b_count = 0, bnb_c_count = 0;

                for(var i=0; i<rts_data.length; i++) {
                    if (rts_data[i].type == "Deck") {
                        data[0][deck_count] = new Object();
                        data[0][deck_count].productName = rts_data[i].productName;
                        data[0][deck_count].coverage    = rts_data[i].coverage;
                        data[0][deck_count].screws      = rts_data[i].screws;
                        data[0][deck_count].gaps        = rts_data[i].gaps;

                        // Insert the data into the Select Box
                        jQuery('#opt_d').append(jQuery('<option>', { value : deck_count }).text(rts_data[i].productName)); 

                        deck_count++;
                    }
                    else if (rts_data[i].type == "Shiplap") {
                        data[1][shiplap_count] = new Object();
                        data[1][shiplap_count].productName = rts_data[i].productName;
                        data[1][shiplap_count].coverage     = rts_data[i].coverage;
                        data[1][shiplap_count].screws       = rts_data[i].screws;
                        data[1][shiplap_count].gaps         = rts_data[i].gaps;

                        // Insert the data into the Select Box
                        jQuery('#opt_s').append(jQuery('<option>', { value : shiplap_count }).text(rts_data[i].productName)); 

                        shiplap_count++;
                    }
                    else if (rts_data[i].type == "Board and Batton - Cap") {
                        data[2][bnb_c_count] = new Object();
                        data[2][bnb_c_count].productName = rts_data[i].productName;
                        data[2][bnb_c_count].coverage   = rts_data[i].coverage;
                        data[2][bnb_c_count].screws         = rts_data[i].screws;
                        data[2][bnb_c_count].gaps       = rts_data[i].gaps;

                        // Insert the data into the Select Box
                        jQuery('#opt_bnb_c').append(jQuery('<option>', { value : bnb_c_count }).text(rts_data[i].productName)); 

                        bnb_c_count++;
                    }
                    else if (rts_data[i].type == "Board and Batton - Base") {
                        data[3][bnb_b_count] = new Object();
                        data[3][bnb_b_count].productName = rts_data[i].productName;
                        data[3][bnb_b_count].coverage   = rts_data[i].coverage;
                        data[3][bnb_b_count].screws         = rts_data[i].screws;
                        data[3][bnb_b_count].gaps       = rts_data[i].gaps;

                        // Insert the data into the Select Box
                        jQuery('#opt_bnb_b').append(jQuery('<option>', { value : bnb_b_count }).text(rts_data[i].productName)); 

                        bnb_b_count++;
                    }
                }

PHP:

<?php
// Connection data
$host = "xxxxxxx";
$username = "xxxxx";
$database = "xxxxx";
$password = "xxxxx";

// Opens a connection to a mySQL server
$connection = mysql_connect ($host, $username, $password);
if (!$connection) {
    die("Not connected : " . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
    die ("Can\'t use db : " . mysql_error());
}

// Set the where clause
$where = "";
switch(@$_GET['type']) {
    case 'shiplap':
        $where = "WHERE type = 'Shiplap'";
    break;

    case 'deck':
        $where = "WHERE type = 'Deck'";
    break;

    case 'bnb_base':
        $where = "WHERE type = 'Board and Batton - Base'";
    break;

    case 'bnb_cap':
        $where = "WHERE type = 'Board and Batton - Cap'";
    break;

    default:
        $where = "";
    break;
}

// Run the query
$query = "SELECT * FROM `site_products` {$where} ORDER BY productID ASC";
$result = mysql_query($query);

if (!$result) {
    die("Invalid query: " . mysql_error());
}

// Declare Variables
$data_shiplap   = array();
$shiplap_i      = 0;

// Get the data and divide
while ($row = @mysql_fetch_assoc($result)) {
    $data_shiplap[$shiplap_i]['productName']    = $row['productName'];
    $data_shiplap[$shiplap_i]['coverage']       = $row['coverage'];
    $data_shiplap[$shiplap_i]['screws']         = $row['screws'];
    $data_shiplap[$shiplap_i]['gaps']           = $row['gaps'];
    $data_shiplap[$shiplap_i]['type']           = $row['type'];

    $shiplap_i++;
}

echo $_GET['callback']. '('. json_encode($data_shiplap) . ')'; 
?>
  • 写回答

1条回答 默认 最新

  • douchenhui5569 2019-01-16 05:25
    关注

    After PHP 5.6.* all mysql_* functions are deprecated. I think that's why you are getting the Internal server error. Replace all the mysql_* functions with mysqli_* and see if the error is persistent.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元