当我对表进行编码时,json_encode会生成一个很长的字符串.到目前为止,我的应用程序可以工作,但字符串最终会太长吗



字符串长度超过612000个字符。我使用Laravel框架在谷歌地图上生成标记,所以它们都必须加载。jsonencode是一种非常方便的方法,但是字符串长得离谱。

在Laravel框架中,我没有使用json_encode,而是使用ajax来检索数据,这样数据就不会暴露在浏览器中。

刀片锉狙击坑:

function initMap() {
// Ajax call to load entire database to a Jquery array
AjaxGet = function () {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $("meta[name='csrf-token']").attr('content')
}
});
var result = $.ajax({
url: "{{url('/ajaxgetter')}}",
method: 'post',
async: false, //obsolete flag, but necessary so that the array does not try to set before data is retrieved
success: function (result) {}
}).responseText;
return result;
}

控制器:

<?php
namespace AppHttpControllers;
use IlluminateSupportFacadesDB;
class AjaxController extends Controller
{
public function index () {return View('ajax');}
public function ajaxgetter() {
return response()->json(DB::select('select * from workorders'), 200);
}
}

相关内容

最新更新