dongmi8980 2018-10-05 11:08
浏览 58

使用PHP,SQL SERVER和AJAX的动态依赖选择框

I have a select that depends on another select, I want to realize it using (PHP, SQL SERVER, JQUERY, AJAX) but I still have this error

ncaught SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at Object. (GenerateQuery.js:29) at fire (jquery-3.3.1_2.js:3268) at Object.fireWith [as resolveWith] (jquery-3.3.1_2.js:3398) at done (jquery-3.3.1_2.js:9305) at XMLHttpRequest. (jquery-3.3.1_2.js:9548)

here is my code

JQUERy :

$('#srces').change(function(){

    var tid=$('#srces').val();

    srcee.attr("disabled", true);
        tab.removeAttr('disabled');
    $.ajax({
      url:'data.php',
      method:"POST",
      data: 'tid6='+tid

    }).done(function(colonn){

      colonn=JSON.parse(colonn);

      $('#tables').empty();
      $('#tables').append('<option selected disabled="disabled">Choisir...</option>');
      colonn.forEach(function(result){
        $('#tables').append('<option value="'+result.nomReal+'">'+result.NomTable+'</option>');
      });
    });
});

data.php :

if(isset($_POST['tid6'])){

        $serverName = "localhost"; //serverName\instanceName
        $connectionInfo = array( "Database"=>"Automatisation", "UID"=>"Dev", "PWD"=>"root");
        $conn = sqlsrv_connect( $serverName, $connectionInfo);
        $sql ="SELECT * FROM Table";
        $stmt = sqlsrv_query($conn, $sql);

        $result = array();
        do {
            while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)){
               $result[] = $row;

            }
        } while (sqlsrv_next_result($stmt));


        sqlsrv_free_stmt($stmt);
        sqlsrv_close($conn); //Close the connnectiokn first

        echo json_encode($result);
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类