0

我需要从删除的项目(使用 jqueryui draggables/droppables/sortables)中提取的元素 id 中获取的数据通过表单(通过电子邮件发送)连同此处的数据一起发送:

      function submitForm() {
$.ajax({type:'POST',
       url: 'send_tile.php',
       data:$('#tiles_collected').serialize(), 
       success: function(response) {
    $('#tiles_collected').find('.form_result').html(response);
}});

return false;
   }

获取ID的功能是这样的(不确定它是否工作正常):

  function getSku() {
var myIds = new array();
        $("#collection li").each(function(index, element){
              alert($(this).attr('id'));
           myIds.push(element.id);

            });

表格如下所示:

     <form id="tiles_collected" name='tiles_collected' method="post" onsubmit="return submitForm();">
      Email:<input name='email' id='email' type='text'/><br />
      Name:<input name='name' id='name' type='text' /><br />
       Zip code: <input name='zip' id='zip' type='text' /><br />
       <input type='hidden' id='sku' />
       <input type="submit" name="submit" value="Email collection to yourself and us" /><br/>
       <div class="form_result"></div>
       </form>

谁能给我一个帮助?

4

1 回答 1

0

要仅将 ID 添加到发送到服务器的数据中,您可以使用扩展或仅将它们添加到 Ajax 函数中。

延长:

function submitForm() {
    var MyData = $('#tiles_collected').serialize();
    $.extend(MyData, {IDs: myIds});  //myIds will have to be accessable, right now it's a local variable in your getSku() function

    $.ajax({type:'POST',
       url: 'send_tile.php',
       data: MyData, 
       success: function(response) {
            $('#tiles_collected').find('.form_result').html(response);
       }
    });
    return false;
}

或者直接添加它们:

function getSku() {
    var myIds = new array();
    $("#collection li").each(function(index, element){
        myIds.push(element.id);
    });
    return myIds;
}

var IDs = getSku();

$.ajax({type:'POST',
    url: 'send_tile.php',
    data: {data : $('#tiles_collected').serialize(), ids : IDs},
    success: function(response) {
        $('#tiles_collected').find('.form_result').html(response);
    }
});
于 2012-04-09T11:47:03.473 回答