dougongnan2167 2013-10-24 19:32
浏览 87

如何从.ajax jquery中的php文件返回值

ajax not returning data from php file i want my the data from php file to be shown on keyup function i used, the php file works fine but show result on next page i want to show it on the same page here is my code

<script>
$(document).ready(function () {
    $("#searchtext").keyup(function () {
        var searchtext = $("#searchtext").val();
        var searchby = $("#searchby").val();
        $.ajax({
            url: "searchtw.php",
            dataType: "html",
            type: 'POST',
            async: true,
            data: {
                searchtxt: searchtext,
                searchby: searchby
            },
            success: function (result) {
                $("#result").append(result);
            }
        });
    });
});
</script>

here is form

<form id="search" enctype="multipart/form-data">
<input type="text" name="searchtext" id="searchtext"  />
</form>
<div id="result"></div>

and here is my php code

<?php
require 'opendb.php';
$offi = $_POST["searchtext"];
$sql="SELECT * FROM abc WHERE tw_UN=$offi";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
echo "<table border='1'>
<tr>
<th>College Number</th>
<th>Name</th>
<th>Session</th>
</tr>
<tr>
<td>" . $row['tw_CN'] . "</td>
<td>" . $row['txtName'] . "</td>
<td>" . $row['numSession'] . "</td>
</tr>";
echo "</table>";
?> 
  • 写回答

1条回答 默认 最新

  • douqiao5543 2013-10-24 19:37
    关注

    Get rid of the <form> tag -- you don't need it if you're not submitting a form. I suspect what's happening is that when the user presses Return, the form is submitting, which is reloading the page.

    评论

报告相同问题?

悬赏问题

  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题