I am making an Ajax call and passing through the time value from a currently playing track. In order to simply add an integer to the database rather than a time such as 242.14835735 I am using math.round. Here is the code:
$.ajax({
type: 'POST',
url: '/updatetimelistened',
data: {
trackID: {{$item->track_id}},
track: "{{$item->track_name}}",
token: "{{$app->token}}",
songbox: "{{$app->songbox}}",
user_id: "{{$app->user_id}}",
time: Math.round(time)
}
});
This process runs thousands of times a day but I am getting infrequent errors; maybe 100 a day where the non rounded integer is passed to the controller.
I’m no JavaScript expert - is this just to be expected that sometimes the math.round won’t take effect?
Any insight appreciated.
Here is the error in full
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type integer: "242.4043537414966"
CONTEXT: unnamed portal parameter = '...' (SQL: insert into "track_times" ("user_id", "track_id", "time_listened", "token", "updated_at", "created_at") values (3445, 19357, 242.4043537414966, lKUA9RHZxgMiKpvPGYeE6ZbWTXX6uLkVIg2EP2xZqL7wA0YJgE, 2022-11-30 15:03:03, 2022-11-30 15:03:03) returning "id")