I'm trying to load database info but it doesn't seem to be working in JSFiddle.

我正在尝试加载数据库信息但它似乎没有在JSFiddle中工作。

HTML:

<table class="table" border="1" cellpadding="0" cellspacing="0">
    <thead>
        <tr>
        <th>Dropdown</th><th>Description From Account</th><th>Other</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td width="20%" id="accountNumber" contenteditable="true"><select data-placeholder="Choose Account . . ." class="chosen-select-newRow" style="width:350px;" tabindex="4"><option value=""></option></select></td><td id="accountDesc" contenteditable="true"></td><td id="branch" contenteditable></td>
        </tr>
        <tr>
            <td width="20%" id="accountNumber" contenteditable="true"><select data-placeholder="Choose Account . . ." class="chosen-select-newRow" style="width:350px;" tabindex="4"><option value=""></option></select></td><td id="accountDesc" contenteditable="true"></td><td id="branch" contenteditable></td>
        </tr>
    </tbody>
</table>

Ajax:

function populate(){
$(function () 
  {
    //-----------------------------------------------------------------------
    // 2) Send a http request with AJAX http://api.jquery.com/jQuery.ajax/
    //-----------------------------------------------------------------------
    $.ajax({                                      
      url: 'journal-populate.php',                  //the script to call to get data          
      data: '',                        //you can insert url argumnets here to pass to api.php
                                       //for example "id=5&parent=6"
      dataType: 'json',                //data format      
      success: function(rows){          
                    for (var i in rows)
                        {
                            var row = rows[i]; 

                            //var account = row[1];         //get id
                            //var description = row[2];     //get account description

                            $('.chosen-select-newRow').append($('<option></option>').val('?acc=' + row[1] + '&desc=' + row[2]).html(row[1] + ' - ' + row[2]));

                            //alert(id + ' ' + account + ' ' + description + ' ' + level1 + ' ' + level2 + ' ' + level3 + ' ' + level4 ); /*'<span onclick="return false;" href="?account='+ row[1] +'&desc='+ row[2] +'">'+*/ /*+'</span>'*/

                        } 
                }
        });
  }); 

}

PHP:

<?php 
  include('dbconn.php');
  //--------------------------------------------------------------------------
  // Example php script for fetching data from mysql database
  //--------------------------------------------------------------------------
  $databaseName = "mochamhy_test";
  $tableName = "accountMaster";

  //--------------------------------------------------------------------------
  // 1) Connect to mysql database
  //--------------------------------------------------------------------------

  $con = mysql_connect($gaSql['server'],$gaSql['user'],$gaSql['password']);
  $dbs = mysql_select_db($databaseName, $con);
  //--------------------------------------------------------------------------
  // 2) Query database for data
  //--------------------------------------------------------------------------

  $result = mysql_query("SELECT * FROM $tableName ORDER BY `accountNumber` ASC");          //query
  //$array = mysql_fetch_array($result);                          //fetch result 
  $data = array();
    while ( $row = mysql_fetch_row($result) )
        {
             $data[] = $row;
        }
  //--------------------------------------------------------------------------
  // 3) echo result as json 
  //--------------------------------------------------------------------------
  echo json_encode($data);

?>

It's working on my localhost, but I can't seem to get it working on a Fiddle. I can even see the JSON data here http://www.mochamedia.co.za/clients/testing/js/journal-populate.php

它正在我的本地主机上工作,但我似乎无法让它在小提琴上工作。我甚至可以在这里看到JSON数据http://www.mochamedia.co.za/clients/testing/js/journal-populate.php

I don't know if it's possible?

我不知道是否可能?

Heres the FIDDLE.

继承了FIDDLE。

Any help or suggestions will be appreciated!

任何帮助或建议将不胜感激!

2 个解决方案

#1


0

Because your jsfiddle can not able to find your php file as well as ajax file containing the function populate() which you calling from window.onload.

因为你的jsfiddle无法找到你的php文件以及包含你从window.onload调用的函数populate()的ajax文件。

So you have to include that files and give appropriate path. jsfiddle gives the option to include external file under the head of External Resources so please try to include all require php files your fiddle going to be works perfectly.

因此,您必须包含该文件并提供适当的路径。 jsfiddle提供了在外部资源的头部包含外部文件的选项,所以请尽量包括所有需要的PHP文件,你的小提琴将完美地工作。

更多相关文章

  1. 教你如何利用php.exe运行php文件
  2. Laravel尝试在根文件夹中存储缓存文件
  3. php之简单的文件管理(基本功能)
  4. 从文本文件中读取,然后决定是否要在php中禁用或启用按钮
  5. php删除指定目录下的的文件/文件夹-用PHP怎么删除某目录下指定的
  6. PHP文件锁同步实例
  7. 我的includes / header.php中的引用CSS文件
  8. 一个简易的PHP读取CSV文件的方法
  9. Php DateTime :: setDate()不在第一个DatePeriod迭代上工作

随机推荐

  1. 图说yield
  2. 开发者必备Linux命令
  3. 翻译社重大改版
  4. JVM故障诊断和处理工具
  5. Linux防火墙Firewall和Iptables的使用
  6. macrotask与microtask
  7. 开发者必备Docker命令
  8. [一些勘误]ubuntu16.04的Python版本,Pytho
  9. 【MySQL】 explicit_defaults_for_timest
  10. 初始化 Java 数据字段(学习 Java 编程语言