weixin_33709609 2011-03-06 19:31 采纳率: 0%
浏览 38

我如何AJAX将此脚本化


I use this script which submits links into a text file. The only problem is, I need the form to post dynamically on the same page. Any ideas on how this can be done? What I'm using:
To post:

<form method="POST" action="addlink.php">
Link: <input type="text name="link">
<input type="submit" name="submit">
</form>

addlink.php:

<?
$link = $_POST['link']; 
$fn = 'textfile.txt'; 
$fp = fopen($fn, "a+");
$write = fputs($fp, $link."<br>");
fclose($fp);
?>

The call:

<?
$fn = 'textfile.txt';
$fp = fopen($fn, "r+");
$info = fread($fp,filesize($fn));
fclose($fp);
echo $info;
?>

Also any ideas on how I could make the script wait to publish the links so I can approve/delete them? I was thinking about MySQL but I'm not very great at writing DB's. I also have the jQuery lib.

  • 写回答

1条回答 默认 最新

  • weixin_33737774 2011-03-06 19:55
    关注

    Check out jQuery's post() API: http://api.jquery.com/jQuery.post/

    jQuery makes it fairly straightforward to use AJAX on a form submission. I think you simply do exactly what you're doing now, but behind the scenes with AJAX, then, if it is successful, just send back some text that will let you know that it worked.

    As far as the approval/denial of links goes, I would just, as you were thinking, set up a MySQL database table with at least the following fields: id, link, approved. Let us know exactly what else you need help with. If there are more specific questions that you have.

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化