脚本宝典收集整理的这篇文章主要介绍了php – 从服务器动态加载数据到“选择”数据表中的输入字段,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经尝试过这段代码,但它没有返回任何内容,或者我应该说一个空值.我确信它应该只返回一行.
这是我的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"}] ?>
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" } ] } );
我似乎无法弄清楚出了什么问题.我错过了什么?你能帮助我吗?
提前致谢!
以上是脚本宝典为你收集整理的php – 从服务器动态加载数据到“选择”数据表中的输入字段全部内容,希望文章能够帮你解决php – 从服务器动态加载数据到“选择”数据表中的输入字段所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。