开发者

Looking for an standard way to post json data on full postback

I wonder if I have any other method but a hidden field to post a JSON object to the server on full postback.

Imagine you have a form (with textboxes, checkboxes, etc) and you need to post a json string when the user post the form. This means开发者_如何学C, I would post all the form values + the json string but I can't come up with any solution but a hidden field.

Just wondering if there is any other option.

Thanks!


Hidden field is your only option. Unless you want to display the JSON to the user, in that case you can put it into a textarea or text input.


I used this recently in my web app:

$('#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);
                        }
                    });
});

Give this a try in your application or post you html and i can form the json...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜