我如何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.

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.