我有一组对象变量,即事件,我想通过ajax将其发布并保存到我的数据库表col中,当我得到事件变量时,它就是这样显示的,
0: {type: 4, data: {…}, timestamp: 1577356630415, delay: 0}
1: {type: 2, data: {…}, timestamp: 1577356630418, delay: 3}
2: {type: 3, data: {…}, timestamp: 1577356630420, delay: -13.656982421875}
3: {type: 3, data: {…}, timestamp: 1577356630923, delay: 39.343017578125}
4: {type: 3, data: {…}, timestamp: 1577356631425, delay: 691.343017578125}
但是我正在使用JSON打印此值。stringify是我们没有显示延迟键值
console.log(JSON.stringify(events));
[{"type":4,"data":{"href":"http://localhost:8888/check/","width":1440,"height":454},"timestamp":1577356630415},{"type":2,"data":{"node":{"type":0,"childNodes":[{"type":1,"name":"html","publicId":"","systemId":"","id":2},{"type":2,"tagName":"html","attributes":{},"childNodes":[{"type":2,"tagName":"head","attributes":{},"childNodes":[{"type":3,"textContent":"\n","id":5},{"type":2,"tagName":"meta","attributes":{"charset":"UTF-8"},"childNodes":[],"id":6},{"type":3,"textContent":"\n","id":7},{"type":2,"tagName":"title","attributes":{},"childNodes":[{"type":3,"textContent":"Title of the document","id":9}],"id":8},{"type":3,"textContent":"\n","id":10},{"type":2,"tagName":"link","attributes":{"rel":"stylesheet","type":"text/css","href":"https://cdn.jsdelivr.net/npm/rrweb@latest/dist/rrweb.min.css"},"childNodes":[],"id":11},{"type":2,"tagName":"link","attributes":{"rel":"stylesheet","type":"text/css","href":"https://cdn.jsdelivr.net/npm/rrweb-player@latest/dist/style.css"},"childNodes":[],"id":12},{"type":2,"tagName":"script","attributes":{"type":"text/javascript","src":"https://cdn.jsdelivr.net/npm/rrweb@latest/dist/rrweb.min.js"},"childNodes":[],"id":13},{"type":2,"tagName":"script","attributes":{"type":"text/javascript","src":"https://cdn.jsdelivr.net/npm/rrweb-player@latest/dist/index.js"},"childNodes":[],"id":14},{"type":2,"tagName":"meta","attributes":{"name":"csrf-token","content":"{{ csrf_token() }}"},"childNodes":[],"id":15},{"type":2,"tagName":"style","attributes":{"type":"text/css"},"childNodes":[{"type":3,"textContent":"body{margin:0}.replayer-wrapper{position:relative}.replayer-mouse{position:absolute;width:20px;height:20px;transition:.05s linear;background-size:contain;background-position:50%;background-repeat:no-repeat;background-image:url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9JzMwMHB4JyB3aWR0aD0nMzAwcHgnICBmaWxsPSIjMDAwMDAwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGRhdGEtbmFtZT0iTGF5ZXIgMSIgdmlld0JveD0iMCAwIDUwIDUwIiB4PSIwcHgiIHk9IjBweCI+PHRpdGxlPkRlc2lnbl90bnA8L3RpdGxlPjxwYXRoIGQ9Ik00OC43MSw0Mi45MUwzNC4wOCwyOC4yOSw0NC4zMywxOEExLDEsMCwwLDAsNDQsMTYuMzlMMi4zNSwxLjA2QTEsMSwwLDAsMCwxLjA2LDIuMzVMMTYuMzksNDRhMSwxLDAsMCwwLDEuNjUuMzZMMjguMjksMzQuMDgsNDIuOTEsNDguNzFhMSwxLDAsMCwwLDEuNDEsMGw0LjM4LTQuMzhBMSwxLDAsMCwwLDQ4LjcxLDQyLjkxWm0tNS4wOSwzLjY3TDI5LDMyYTEsMSwwLDAsMC0xLjQxLDBsLTkuODUsOS44NUwzLjY5LDMuNjlsMzguMTIsMTRMMzIsMjcuNThBMSwxLDAsMCwwLDMyLDI5TDQ2LjU5LDQzLjYyWiI+PC9wYXRoPjwvc3ZnPg==)}.replayer-mouse:after{content:\"\";display:inline-block;width:20px;height:20px;border-radius:10px;background:#4950f6;transform:translate(-10px,-10px);opacity:.3}.replayer-mouse.active:after{animation:a .2s ease-in-out 1}@keyframes a{0%{opacity:.3;width:20px;height:20px;border-radius:10px;transform:translate(-10px,-10px)}50%{opacity:.5;width:10px;height:10px;border-radius:5px;transform:translate(-5px,-5px)}}","isStyle":true,"id":17}],"id":16}],"id":4},{"type":3,"textContent":"\n\n","id":18},{"type":2,"tagName":"body","attributes":{},"childNodes":[{"type":2,"tagName":"script","attributes":{"src":"http://localhost:8888/check/js/jquery-3.2.1.min.js"},"childNodes":[],"id":20},{"type":3,"textContent":"\n ","id":21},{"type":2,"tagName":"script","attributes":{"src":"http://127.0.0.1:8000/js/api.js","onload":"uxSpy('35077yr0iqb')"},"childNodes":[],"id":22},{"type":3,"textContent":"\n","id":23},{"type":2,"tagName":"pre","attributes":{},"childNodes":[{"type":3,"textContent":"\nContent of the document......\n\n","id":25}],"id":24}],"id":19}],"id":3}],"id":1},"initialOffset":{"left":0,"top":0}},"timestamp":1577356630418},{"type":3,"data":{"source":1,"positions":[{"x":122,"y":29,"id":24,"timeOffset":0}]},"timestamp":1577356630420},{"type":3,"data":{"source":1,"positions":[{"x":130,"y":29,"id":24,"timeOffset":-450},{"x":133,"y":29,"id":24,"timeOffset":-394},{"x":134,"y":31,"id":24,"timeOffset":-339},{"x":134,"y":37,"id":24,"timeOffset":-282},{"x":134,"y":42,"id":24,"timeOffset":-227},{"x":134,"y":43,"id":24,"timeOffset":-147},{"x":134,"y":43,"id":24,"timeOffset":-92}]},"timestamp":1577356630923},{"type":3,"data":{"source":1,"positions":[{"x":134,"y":49,"id":24,"timeOffset":-300},{"x":158,"y":199,"id":3,"timeOffset":-245},{"x":173,"y":303,"id":3,"timeOffset":-189}]},"timestamp":1577356631425},{"type":3,"data":{"source":1,"positions":[{"x":181,"y":332,"id":3,"timeOffset":-295},{"x":200,"y":341,"id":3,"timeOffset":-245},{"x":224,"y":355,"id":3,"timeOffset":-192},{"x":233,"y":364,"id":3,"timeOffset":-136}]},"timestamp":1577356631927}]5: {type: 3, data: {…}, timestamp: 1577356631927, delay: 1198.343017578125}`
答案 0 :(得分:0)
您应该发布完整的代码。您的错误出在其他地方,因为当您仅使用提供的数据创建事件对象并对其进行字符串化时,输出将如预期的那样:
var events = {
0: {type: 4, data: {}, timestamp: 1577356630415, delay: 0},
1: {type: 2, data: {}, timestamp: 1577356630418, delay: 3},
2: {type: 3, data: {}, timestamp: 1577356630420, delay: -13.656982421875},
3: {type: 3, data: {}, timestamp: 1577356630923, delay: 39.343017578125},
4: {type: 3, data: {}, timestamp: 1577356631425, delay: 691.343017578125}
}
console.log(JSON.stringify(events));