duancheng3042 2016-02-26 18:36
浏览 48

php jquery显示来自mysql getjson的数据

I need to show data retrieved from mysql in a page. My codes are :

jquery:

$('#search').on('click', function() { 
        alert($('.search_word').val());
        var data_to_php = $('.search_name:visible').val(); //take the text only from the visible search box
        alert(data_to_php);


        //////////////////////////////////////////////////////////////////////
        //The following code will get the search list populated  by //////////
        //retrieving data from mysql table////////////////////////////////////
        //////////////////////////////////////////////////////////////////////

        $.getJSON('./search.php', 'keyword='+data_to_php, function(info) {

                $.each(info, function() {
                    $('ul.search_list').append('<li   class="search_data">hi</li>'); //this code is for the purpose of testing only

                    console.log(info);
                }); 


        });

    }); //end #search.on.click

the php code is :

require(connect.php);

$keywords = $_GET['keyword'];

$query = "SELECT name FROM test ORDER BY name WHERE name LIKE   '%".$_GET['keyword']."%'";

$result = mysqli_query($conn,$query); //connection variable
                                      //$conn is from
                                      //included file
                                      //connect.php 

$jsonData = array();

while($row = mysqli_fetch_array($result)){

    $jsonData[] = $row;

}

echo json_encode($jsonData);
?>

In console.log output, I am getting :

GET ./search.php?keyword=s 500 Internal Server Error with blank response. Internal error 500 can as well be generated if php is not working properly. There might also be some error in the code.

Now phpinfo is showing results properly.

How do I know if the getjson call to php script is successful?

  • 写回答

1条回答 默认 最新

  • dongmei1988 2016-02-26 18:43
    关注

    There is an error in your MySQL query, you cannot call ORDER BY before WHERE clause, modify your query,

    SELECT name FROM test WHERE name LIKE '%".$_GET['keyword']."%' ORDER BY name

    A very good reference to know the correct order of execution in MySQL - MySQL query / clause execution order

    Also, your file name in the require function should be enclosed within quotes - require('connect.php');

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据