Jquery 传递给Symfony\Component\HttpFoundation\Response::setContent()的TypeError参数1的类型必须为string或null,对象为给定的,
我使用下面的代码,我需要从服务器获取Jquery 传递给Symfony\Component\HttpFoundation\Response::setContent()的TypeError参数1的类型必须为string或null,对象为给定的,,jquery,laravel,pusher,Jquery,Laravel,Pusher,我使用下面的代码,我需要从服务器获取time(),我在laravel中使用了推送器和队列 我使用的html(刀片文件)带有3个div,如下所示 <div id="divId1">0</div> <div id="divId2">0</div> <div id="divId3">
time()
,我在laravel中使用了推送器和队列
我使用的html(刀片文件)带有3个div,如下所示
<div id="divId1">0</div>
<div id="divId2">0</div>
<div id="divId3">0</div>
在js文件中
$(document).ready(function(){
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
document.querySelectorAll('*').forEach(function(node) {
var data = '';
ajax = $.ajax({
url: '/getTime/' . node,
method: 'get',
success: function(data) {
//parse the server side response
console.log(data);
}
});
});
});
var pusher = new Pusher('xxxxxxxxxxxxxxx', {
cluster: 'eu',
encrypted: true
})
var channel = pusher.subscribe('time-updated');
// Binding a function to a Event
channel.bind('App\Events\TimeUpdated', function(data){
console.log(data);
});
class TimeUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $timechanged, $divID;
public function __construct($divID, $timechanged)
{
$this->timechanged = $timechanged;
$this->divID = $divID;
}
public function broadcastOn()
{
return new Channel('time-updated');
}
}
事件文件
$(document).ready(function(){
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
document.querySelectorAll('*').forEach(function(node) {
var data = '';
ajax = $.ajax({
url: '/getTime/' . node,
method: 'get',
success: function(data) {
//parse the server side response
console.log(data);
}
});
});
});
var pusher = new Pusher('xxxxxxxxxxxxxxx', {
cluster: 'eu',
encrypted: true
})
var channel = pusher.subscribe('time-updated');
// Binding a function to a Event
channel.bind('App\Events\TimeUpdated', function(data){
console.log(data);
});
class TimeUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $timechanged, $divID;
public function __construct($divID, $timechanged)
{
$this->timechanged = $timechanged;
$this->divID = $divID;
}
public function broadcastOn()
{
return new Channel('time-updated');
}
}
Routes.php
Route::get('/getTime/{id}', 'App\Http\Controllers\TimeController@getTime');
php artisan队列:work
[2021-05-10 06:22:51][1] Processing: App\Jobs\TimeChange
[2021-05-10 06:22:51][1] Failed: App\Jobs\TimeChange
[2021-05-10 06:22:51][2] Processing: App\Jobs\TimeChange
[2021-05-10 06:22:51][2] Failed: App\Jobs\TimeChange
[2021-05-10 06:26:13][3] Processing: App\Jobs\TimeChange
[2021-05-10 06:26:13][3] Failed: App\Jobs\TimeChange
有人能帮忙吗
[2021-05-10 06:22:51][1] Processing: App\Jobs\TimeChange
[2021-05-10 06:22:51][1] Failed: App\Jobs\TimeChange
[2021-05-10 06:22:51][2] Processing: App\Jobs\TimeChange
[2021-05-10 06:22:51][2] Failed: App\Jobs\TimeChange
[2021-05-10 06:26:13][3] Processing: App\Jobs\TimeChange
[2021-05-10 06:26:13][3] Failed: App\Jobs\TimeChange