<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>serialise</title> <script src="jquery.js" type="text/javascript"></script> </head> <body> <form id="formId" action=""> <input type="text" name="a" value="安安" /> <input type="hidden" name="b" value="abc"> </form> <script type="text/javascript"> $(function(){ var formStr=$('#formId').serialize(); //序列化中文時之所以亂碼是因為.serialize()調用了encodeURLComponent方法將數據編碼了 //原因:.serialize()自動調用了encodeURIComponent方法將數據編碼了 //解決方法:調用decodeURIComponent(XXX,true);將數據解碼 params = decodeURIComponent(formStr,true); //關鍵點 alert(formStr+'\n'+params); $.ajax({ 'type':'post', 'url':'c.php', 'data':formStr, success:function(msg){ alert(msg); } }) }) </script> </body> </html>
<?php $strA=$_POST['a']; $strB=$_POST['b']; echo $strA."____".$strB;