AJAX, Javascript, HTML & Arduino

Timing Control for Arduino interface use.
The current architecture of my equipment is the following ARDUINO MEGA, W5500, DS3231.
The system controls a poultry farm in relation to the delivery of feed, water, lighting and water delivery. The application shows in a first web page the updated data of the different sensors, then to change the parameters of use, I use a second web page.
The problem I have is the following: When recording in the SD, the Arduino manipulates ports 4 and 10 through SPI. These ports control SD (port 4) and ETHERNET (port 10). The specific characteristic of use by the manufacturer indicates that one should be used at the same time and not both. On the other hand, the application, every time an action is generated, is recorded in the SD in a file with which analyzes are carried out later. As long as there is no WEB user there is no problem, all the action of the arduino is perfect.
However, when a client is active, AJAX works, returning the parameters to be displayed, when the external action of feeding the birds occurs, a record is generated and when I proceed to record in the file, the WEB server crashes, so before explained.
I declared a variable that tells me that it is ready to record in the SD and I have made several attempts to pause or stop AJAX through JAVASCRIPT.
Any recommendation?