2011-02-13 72 views
1

我已經使用.serialize()完成了一個函數。jQuery - do .serialize()正確的轉義?

這是函數:

$('form[name=contactForm]').submit(function(e){ 
    e.preventDefault(); 
    $.ajax({ 
     type: 'POST', 
     cache: false, 
     url: './ajax/header_ajax.php', 
     data: 'id=header_contact_send&'+$(this).serialize(), 
     success: function(msg) { 
      $("#boxContentId").html(msg); 
     } 
    }); 
}); 

如果我把我的輸入框中輸入某個值作爲 我看到他們是正確processend和功能的工作。如何可能?它應該使'id=header_contact_send&'+$(this).serialize(),

混淆序列化()函數的字符串轉義?

回答

6

基本上,在this file中實現序列化。它結束調用,對於每個值對,即內部jQuery.param定義的函數:

add = function(key, value) { 
// If value is a function, invoke it and return its value 
value = jQuery.isFunction(value) ? value() : value; 
s[ s.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value); 
}; 

所以逸出通過調用本地javascript函數encodeURIComponent完成。

我希望這會幫助你,

傑羅姆·瓦格納

+0

不錯!所以我認爲我可以信任這個功能,而不需要做更多的事情:) – markzzz 2011-02-13 21:59:47