2011-12-20 81 views
0

我需要关于jQuery和ajax的帮助。提交后需要从文件中加载textarea内容。 无法弄清楚这一点。下面的代码:jquery表单提交和textarea刷新

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta name="generator" content= 
    "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" /> 
    <style type="text/css"> 
/*<![CDATA[*/ 
    #output { 
     resize: none; 
     width:100%; 
     height:70%; 
    } 
    #time { 
     background-color:#0F0; 
    } 
    #command { 
     width:80%; 
    } 
    #submit { 
     width:18%; 
    } 
    /*]]>*/ 
    </style> 
    <script type="text/javascript" src="jquery.js"> 
</script> 
    <script type="text/javascript"> 
//<![CDATA[ 
      $(document).ready(function() { 
       var psconsole = $('#output'); 
       psconsole.scrollTop(
       psconsole[0].scrollHeight - psconsole.height()); 
      }); 

      $(document).ready(function() { 
       $("#execute").validate({ 
        debug: false, 
        rules: { 
         name: "required", 
         email: { 
          required: true, 
          email: true 
         } 
        }, 
        messages: { 
         name: "Please let us know who you are.", 
         email: "A valid email will help us get in touch with you.", 
        }, 
        submitHandler: function (form) { 
         // do other stuff for a valid form 
         $.post('ajax.php', $("#execute").serialize(), function (data) { 
          $('#output').html(data); 
         }); 
        } 
       }); 
      });   
    //]]> 
    </script> 
    <meta http-equiv="Content-Type" content="text/html; charset=us-ascii" /> 

    <title></title> 
</head> 

<body> 
    <textarea readonly="readonly" cols="150" id="output"> 
<?php 
    echo $api->consoleOutput(50, 0); ?> 
</textarea> 

    <form action="" name="execute" method="post" id="console"> 
    <input type="text" id="command" name="command" /> <input type="submit" id="submit" 
    value="si&Aring;&sup3;sti" /> <button id="button">siusti</button> 
    </form><?php 
     $api->sendCommand($_POST['command']) 
     ?> 
</body> 
</html> 

我已经试过了,似乎并没有帮助快速解答... 规则#1中的所有其他方法;)

+0

你还需要包含插件,通常它被命名为'jquery.validate.js' – 2011-12-20 13:55:43

+0

这实际上有效,谢谢:) – 2011-12-20 14:13:41

+0

干杯,编辑我的答案以及然后。 – 2011-12-20 14:24:44

回答

0

你的表格ID是“控制台”,而不是 “执行”,因此改变这一行:

$("#execute").validate({ 

要这样:

$("#console").validate({ 

可以也选择它的名字的形式,但在这看不出任何优势。

编辑:为了所有这些工作,您还必须引用插件本身,通常名为jquery.validate.js

+0

,但#输出仍然不刷新.. – 2011-12-20 13:29:45

+0

@Justas如果您在'$ .post()'方法内添加'alert(data);',您看到了什么? – 2011-12-20 13:39:52

+0

好吧,其实没什么...这不是我的代码,所以这可能不会工作... – 2011-12-20 13:42:37