2010-06-07 58 views
0

Im'trying提交表單而不刷新頁面,但我有問題。 當我點擊提交頁面刷新和齒輪張貼。 這是代碼,我做錯了什麼? (我是一個新手)jQuery.Form將不會提交

jQuery 1.4.2和jQuery表單插件2.43是存在的。

TNX

$(document).ready(function() { 
    var options = { 
     target:  '#output2', 
     url:  https://graph.facebook.com/<%=fbUid%>/feed, 
     type:  post, 

     clearForm: true  // clear all form fields after successful submit 
     //dataType: null  // 'xml', 'script', or 'json' (expected server response type) 
     //resetForm: true  // reset the form after successful submit 

     // $.ajax options can be used here too, for example: 
     //timeout: 3000 
    }; 

    // bind to the form's submit event 
    $('#fbPostStatus').submit(function() { 
     // inside event callbacks 'this' is the DOM element so we first 
     // wrap it in a jQuery object and then invoke ajaxSubmit 
     $(this).ajaxSubmit(options); 

     // !!! Important !!! 
     // always return false to prevent standard browser submit and page navigation 
     return false; 
    }); 
}); 
+1

使用像Firebug(用於Firefox),Chrome開發工具(用於Chrome),Microsoft Script Debugger或Visual Studio(用於IE)等等的調試器等等**真正值得**,以遍歷代碼。任何這些都會揭示Pekka和jAndy指出的腳本錯誤。 – 2010-06-07 10:38:46

回答

2

你缺少引號在url屬性:

url:  https://graph.facebook.com/<%=fbUid%>/feed, 

需求是

url:  "https://graph.facebook.com/<%=fbUid%>/feed", 

導致JavaScript錯誤。 onsubmit函數中的錯誤使瀏覽器回到默認行爲狀態(即以正常方式發送表單)。

而@jAndy指出,post也需要一些引號。

+0

實際上錯誤是在'ready'中,所以提交處理程序甚至沒有連接。 – 2010-06-07 10:37:44

+1

'post'需要一些報價以及 – jAndy 2010-06-07 10:37:54

+0

我有引用帖子和網址,並且網站停止重新加載。該表單似乎提交(好了,textarea清除),但沒有任何東西被髮布。我必須調查。 – kim 2010-06-07 10:52:05