【问题标题】:How can I retrieve json stringified objects in php?如何在 php 中检索 json 字符串化对象?
【发布时间】:2013-02-09 10:25:31
【问题描述】:

我使用下面的代码 sn-p 向服务器发送了一些数据,但我不知道如何使用 PHP 检索返回的数组。感谢您的任何建议。

$('.ticket-row').each(function() {
tickets.push({ id : $(this).attr('id'),
              no : $(this).find('#no').text(),
              c_name : $(this).find('#c_name').val(),
              next_of_kin: $(this).find('#next_of_kin').val(),
              address : $(this).find('#address').val(),
              seat_no : $(this).find('#seat_no').val(),
              fare : $(this).find('#fare').val() });
});

$.ajax({
    type : 'POST',
    url : '**URL_HERE**',
    data : JSON.stringify(tickets),
    dataType : 'json'
});

【问题讨论】:

标签: php javascript jquery json stringify


【解决方案1】:

我想你想使用类似的东西

'posted_data=' + encodeURIComponent(JSON.stringify(tickets))

然后,在 PHP 端你可以用

$posted_data = $_POST['posted_data'];
$data = json_decode($posted_data);

除了使用JSON.stringify,您还可以使用 JSON 作为数据,jQuery 会将其转换为查询字符串作为请求的一部分。然后,您可以使用$_POST 中的各个组件。

【讨论】:

  • 非常感谢,这对我来说效果很好,我可以弄清楚其余的。
猜你喜欢
  • 2019-10-03
  • 2018-05-18
  • 2016-09-04
  • 1970-01-01
  • 1970-01-01
  • 2012-09-30
  • 1970-01-01
  • 2013-03-23
  • 1970-01-01
相关资源
最近更新 更多