寻找一种在完整回发上发布json数据的标准方法

时间:2010-11-24 14:41:51

标签: javascript asp.net json


我想知道我是否有任何其他方法,但有一个隐藏字段,以便在完全回发时将JSON对象发布到服务器。

想象一下你有一个表单(带有文本框,复选框等),你需要在用户发布表单时发布一个json字符串。这意味着,我会发布所有表单值+ json字符串,但我不能提出任何解决方案,但隐藏字段。

只是想知道是否还有其他选择。

谢谢!

2 个答案:

答案 0 :(得分:1)

隐藏字段是您唯一的选择。除非您想向用户显示JSON,否则您可以将其放入textarea或文本输入中。

答案 1 :(得分:0)

我最近在我的网络应用中使用了这个:

$('#submit').live('click',function(){ 

  var postData = {};
  $('#items tr').not(':first').each(function(index, value) {
   var keyPrefix = 'data[' + index + ']';
   postData[keyPrefix + '[index]'] = index;
   postData[keyPrefix + '[supp_short_code]'] = $(this).closest('tr').find('.supp_short_code').text();
   postData[keyPrefix + '[project_ref]'] = $(this).closest('tr').find('.project_ref').text();
   postData[keyPrefix + '[om_part_no]'] = $(this).closest('tr').find('.om_part_no').text();
   postData[keyPrefix + '[description]'] = $(this).closest('tr').find('.description').text();
   postData[keyPrefix + '[quantity_input]'] = $(this).closest('tr').find('.quantity_input').val();
   postData[keyPrefix + '[cost_of_items]'] = $(this).closest('tr').find('.cost_of_items').text();
   postData[keyPrefix + '[cost_total_td]'] = $(this).closest('tr').find('.cost_total_td').text();
  });

                $.ajax
                    ({
                    type: "POST",
                    url: "order.php",
  dataType: "json",
                    data: postData,
                    cache: false,
                    success: function(order_id)
                        {
    alert("Order Saved");
    $('#assigned_id').html(order_id);
                        }
                    });
});

在您的应用程序中试一试或发布html,我可以形成json ...