Serialize a <ul>’s contents and submit form via AJAX
我需要一些帮助来获取通过 AJAX 发布表单请求提交的序列化
<DDPB1>
HTML:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<form id="update_fruit_form" method="post" action="/update_fruits" accept–charset="UTF-8"> <ul id="list_a"> <li id="item_Apple" value="1">Red </li> <li id="item_Green" value="2">Pear <li id="item_Banana" value="3">Yellow <input type="submit" value="Submit"> |
jQuery:
1
2 3 4 5 6 7 8 9 |
$("#update_fruit_form").submit(function() {
$.ajax({ url:"update_fruits.html", context:"#list_a" , success: function(){ $(this).addClass("done"); } }); }); |
谢谢!
1
2 3 4 5 6 7 8 9 10 11 12 13 14 |
var list = {};
$(‘#list_a li’).each(function(){ list[ $(this).attr(‘value’) ] = $(this).html(); }); $("#update_fruit_form").submit(function() { |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/268765.html