关于javascript:序列化一个 的内容并通过 AJAX 提交表单 | 珊瑚贝

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” acceptcharset=“UTF-8”>
  <ul id=“list_a”>
    <li id=“item_Apple” value=“1”>Red
</li>

    <li id=“item_Green” value=“2”>Pear
</li>

    <li id=“item_Banana” value=“3”>Yellow
</li>

 
</ul>

  <input type=“submit” value=“Submit”>
</form>

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() {
    $.ajax({
      url:“update_fruits.html”,
      data: list,
      success: function(){
       $(this).addClass(“done”);
      }
    });
 });


来源:https://www.codenong.com/7707000/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9669.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?