2011-02-13 67 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