Try adding an "action" attribute to the form. Try first with an empty
one: action=""
In theory the form won't submit without an action.
Karl Rudd
On 1/25/07, Massimiliano Marini <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I want to save data typed into a form in to a simple file
> with a script file write in PHP.
>
> I must use $.ajax or $.post? Well, both don't work for me, sure
> I'm in error but where?
>
> index.htm
> <MyHtmlCode>
> <html>
> <head>
> <title> jquery </title>
> <script type="text/javascript" src="jquery.js"></script>
> <script type="text/javascript">
> $(document).ready(function(){
> $("#myForm").submit(function(){
> var testoForm = $("[EMAIL PROTECTED]").val();
> /* With this code don't work */
> $.ajax({
> type: "POST",
> url: "script.php",
> data: "ValoreForm="+testoForm,
> success: function(){$("#output").html("Written data with success!");}
> });
> /* The same with this code */
> $.post("script.php");
> });
> });
> </script>
> </head>
>
> <body>
> <form id="myForm" method="post">
> <input type="text" name="testo">
> <input type="submit" name="submit" value="salva">
> </form>
>
> <div id="output">Ajax response will replace this content.</div>
> </body>
> </html>
> </MyHtmlCode>
>
> This is a stupid PHP code which I verify if the script go in function
> creating a txt file with a simple text inside
> // script.php
> <MyPHPCode>
> <?php
> $f = "db.txt";
> $t = "Hello JQuery!";
> $fh = fopen($f, 'wa') or die("Error!!!");
> fwrite($fh,$t);
> fclose($fh);
> ?>
> </MyPHPCode>
>
> --
> Massimiliano Marini - http://www.linuxtime.it/massimilianomarini/
> "It's easier to invent the future than to predict it." -- Alan Kay
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/