2010-02-23 127 views
0

我想使用malsup jquery表單插件,我不能得到簡單的例子工作(http://jquery.malsup.com/form/#ajaxForm)。我在下面粘貼了我的代碼。出了什麼問題?發生的只是我收到一個警告框,上面寫着「感謝您的評論!」。沒有其他事情發生Ajax,jquery表單插件將無法正常工作

感謝,

馬克

這是ajaxtest.html文件:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <script type="text/javascript" src="javascript/jquery.js"></script> 
    <script type="text/javascript" src="javascript/jquery.form.js"></script> 
    <script type="text/javascript"> 
     // wait for the DOM to be loaded 
     $(document).ready(function() { 

    var options = { 
    target: '#output1', // target element(s) to be updated with server response 
    beforeSubmit: showRequest, // pre-submit callback 
    success: showResponse // post-submit callback 
    }; 

      // bind 'myForm' and provide a simple callback function 
      $('#myForm').ajaxForm(function() { 
       alert("Thank you for your comment!"); 
     }); 
     }); 
    function showRequest(formData, jqForm, options) { 
    alert("calling before sending!"); 
    return true; 
    } 
    function showResponse(responseText, statusText, xhr, $form) { 
    alert("this is the callback post response"); 
    } 
    </script> 
<script> 

</script> 
</head> 
<body> 
<form id="myForm" action="form/report.php" method="post"> 
    Name: <input type="text" name="name" /> 
    Comment: <textarea name="comment"></textarea> 
    <input type="submit" value="Submit Comment" /> 
<div id="output1"></div> 
</form> 
</body> 
</html> 

這是PHP文件:


​​
+0

你檢查過firebug控制檯是否有任何js錯誤? – 2010-02-23 15:12:24

回答

0

您不使用任何地方的options變量,您只定義它。

+0

謝謝 - 這是問題所在。我很感激! – Mark 2010-02-24 01:32:32

0

您需要將您的「選項」對象傳遞給ajaxForm調用,並在該對象中設置成功函數(即在選項對象中)。看到這個頁面:http://jquery.malsup.com/form/#options-object

+0

非常感謝!這是問題。它是一個新的錯誤,但你必須在某個時候開始學習。 – Mark 2010-02-24 01:32:04