如何使搜索txt文件并显示输入值?
我的目录上的文件是这样的:
index.html
mobile.txt
adress.txt
country.txt
我的html是这样的:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myform" method="post">
<input type="text" id="nameTxt" placeholder="Please Enter Your txt name hire"/>
<input type="submit" id="findTxt" value="search"/>
</form>
我想显示搜索结果的内容:
<input type="text" id="diplayTxt" value=""/>
我尝试了一下,但它仍然失败:
$(document).ready(function(){
$("#myform").submit(function (event){
event.preventDefault()
var obj = document.getElementById("nameTxt").value;
var dTxt = document.getElementById("diplayTxt");
$.post("index.php", {obj:obj}, function(data){
dTxt.value = data;
});
});
});
这是PHP代码:
<?php
$ft = $_POST['obj'];
$fh = fopen($ft.".txt", "r");
while ($line = fgets($fh))
{
echo $line;
}
fclose($fh);
?>
请帮助我修复它。
My files on my directory are like this:
index.html
mobile.txt
adress.txt
country.txt
My HTML is like this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myform" method="post">
<input type="text" id="nameTxt" placeholder="Please Enter Your txt name hire"/>
<input type="submit" id="findTxt" value="search"/>
</form>
I want to display the contents of the search results:
<input type="text" id="diplayTxt" value=""/>
I tried this but it still fails:
$(document).ready(function(){
$("#myform").submit(function (event){
event.preventDefault()
var obj = document.getElementById("nameTxt").value;
var dTxt = document.getElementById("diplayTxt");
$.post("index.php", {obj:obj}, function(data){
dTxt.value = data;
});
});
});
Here is the PHP code:
<?php
$ft = $_POST['obj'];
$fh = fopen($ft.".txt", "r");
while ($line = fgets($fh))
{
echo $line;
}
fclose($fh);
?>
Please help me to fix it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论