jQuery ajax中數據以鍵值對(Key/Value)的形式發送到服務器,使用ajax提交表單數據時可以使用jQuery ajax的serialize() 方法表單序列化為鍵值對(key1=value1&key2=value2…)后提交。serialize() 方法使用標准的 URL-encoded 編碼表示文本字符串。下面是使用serialize()序列化表單的實例:
$.ajax({ type: "POST", url: ajaxCallUrl, data: "Key=Value&Key2=Value2", success: function(msg){alert(msg);} });
ajax serialize():
$.ajax({ type: "POST", url:ajaxCallUrl, data:$('#formID').serialize(),// 要提交的表單 success: function(msg) {alert(msg);} });
實例: