欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

jQuery ajax中使用serialize()方法提交表单数据示例

程序员文章站 2023-08-26 09:14:27
jquery ajax中数据以键值对(key/value)的形式发送到服务器,使用ajax提交表单数据时可以使用jquery ajax的serialize() 方法表单序列...
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);}
     });

实例:
jQuery ajax中使用serialize()方法提交表单数据示例