php – 从服务器动态加载数据到“选择”数据表中的输入字段
发布时间:2020-12-13 22:50:56 所属栏目:PHP教程 来源:网络整理
导读:我有一个 PHP代码,由函数加载器调用,只在datatable中的onInitCreate事件上触发.我想要做的是,当用户点击添加按钮时,它必须在选择字段中加载教员名称. 我已经尝试过这段代码,但它没有返回任何内容,或者我应该说一个空值.我确信它应该只返回一行. 这是我的PHP
我有一个
PHP代码,由函数加载器调用,只在datatable中的onInitCreate事件上触发.我想要做的是,当用户点击添加按钮时,它必须在选择字段中加载教员名称.
我已经尝试过这段代码,但它没有返回任何内容,或者我应该说一个空值.我确信它应该只返回一行. getFacultyNames.php <?php error_reporting(-1); require_once("config.php"); $sql="SELECT lastName,firstName,middleName FROM table_faculty"; $result = mysql_query($sql); $stack=array(); if($result === FALSE) { die(mysql_error()); // TODO: better error handling } while($row = mysql_fetch_array($result)) { $name = $row[0].",".$row[1]." ".$row[2]; array_push($stack,array("label" => $name,"value" => $name)); } echo json_encode($stack); //here it returns [{"label":"Last,First Middle","value":"Last,First Middle"}] ?> jquery代码: function loader(){ $.ajax({ "url": 'php/getFacultyNames.php',"async": false,"dataType": 'json',"success": function (json) { console.log( json ); //the getFacultyNames.php is now returning correct values,//but how would I be able to get the value of the json code properly? //it always throws an error ""parsererror" SyntaxError //is it proper to have a code `return json;` in this success function? },"error" : function( jqXHR,textStatus,errorThrown ){ console.log( jqXHR,errorThrown ); } }); } 这是我的编辑器初始化代码: var editor = new $.fn.dataTable.Editor( { "ajaxUrl": "php/table.facultyloading.php","domTable": "#facultyloading","events": { "onInitCreate":function (){ editor.add( { "label": "Assign to Faculty","name": "facultyName","type": "select","ipOpts":loader() // Returns array of objects - .ajax() with async: false }); } },"fields": [ { "label": "Subject Name","name": "name","ipOpts": [ { "label": "sample","value": "sample" } ] },{ "label": "Day","name": "day","default": "Monday","type": "checkbox","ipOpts": [ { "label": "Monday ","value": "Monday " },{ "label": " Tuesday ","value": " Tuesday " },{ "label": " Wednesday ","value": " Wednesday " },{ "label": " Thursday ","value": " Thursday " },{ "label": " Friday ","value": " Friday " },{ "label": " Saturday","value": " Saturday" } ],"separator": "|" },{ "label": "Start Time","name": "startTime","type": "text" },{ "label": "End Time","name": "endTime",{ "label": "Room","name": "room","type": "text" } ] } ); 我似乎无法弄清楚出了什么问题.我错过了什么?你能帮助我吗? 解决方法
我已经将mysql函数转换为PDO_MySQL,最后它的工作原理是我的新getFacultyNames.php,我也修改了我的jquery代码.感谢你的帮助! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |