Jquery:未捕获的TypeError非法调用

时间:2016-04-14 06:22:01

标签: javascript php jquery mysql mysqli

我正在关注网页以了解如何在没有页面刷新的情况下显示来自mysql的数据: - http://talkerscode.com/webtricks/load%20data%20from%20database%20without%20page%20refresh%20using%20ajax%20and%20jquery.php

以下是2个文件 File1:displaydata.html



<html>

<head>
  <script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
  <script type="text/javascript">
    function load_data() {

      var name = document.getElementById("guestname");

      if (name) {
        $.ajax({
          url: 'loaddata.php',
          type: 'POST',
          data: {
            guest_name: name,
          },
          success: function(response) {

            // We get the element having id of display_info and put the response inside it
            $('#display_info').html(response);
            //document.getElementById('display_info').innerHTML = response;
          }
        });

      } else {
        $('#display_info').html("Please Enter Some Words");
      }

    }
  </script>

</head>

<body>

  <input type="text" name="guestname" id="guestname" onKeyUp="load_data();">

  <div id="display_info">

  </div>


</body>

</html>
&#13;
&#13;
&#13;

File2:loaddata.php

&#13;
&#13;
<?php
$host='localhost';
$user='root';
$pw='';
$db='yoigo';
$connect = new mysqli($host, $user, $pw, $db);
if(mysqli_connect_errno()){
	printf("Connect failed: %s\n",mysqli_connect_error());
	exit();
} else {
	echo "Jatinder!";
}

if( isset( $_POST['guest_name'] ) )
//if(1)
{

$name = $_POST['guest_name'];

$sql = " SELECT lastname,email FROM myguests WHERE firstname LIKE '$name%' ";

$result = $connect->query($sql);

if($result === false) {
  trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $conn->error, E_USER_ERROR);
} else {
  $rows_returned = $result->num_rows;
}
echo $rows_returned . ' rows returned.' . '<br> <br>';

	if ($rows_returned > 0) {
		while ($row = mysqli_fetch_array($result, MYSQLI_NUM)){
			echo "<p>".$row[0]."</p>";
			echo "<p>".$row[1]."</p>";
		}	
	}
}
?>
&#13;
&#13;
&#13;

我对jquery的非法调用错误感到沮丧。不知道为什么它会来。有人可以指导吗?

谢谢, Jatinder

0 个答案:

没有答案