// 方法1
var datastring = $("#form").serialize();
$.ajax({
type: "POST",
url: "test.php",
data: datastring,
success: function(data) {
alert('Data send');
}
});
//方法2
var form = $(this).closest('form');
var data = form.serializeArray();
data.push({name: "fun", value: 'img_edit'}); //增加自訂的值
data.push({name: "time", value: $.now()}); //增加自訂的值
data = $.param(data);
$.ajax({
type: "POST",
url: "test.php",
data: data,
success: function(data) {
alert('Data send');
}
});
test.php 測試
<?php
print_r($_POST);
exit;
?>
結果
Array (
[mail] => ann71727@test.com.tw
[password] => asdfasdf
[name] => test
[sex] => 1
)
https://api.jquery.com/serialize/
如果文章對您很有幫助
請我喝杯咖啡吧
Bitcoin 比特幣錢包:
38ieWXhURt27br9XrDoCeo4eruzKyi8QKs
Post Views: 1,820