Thank you for your help. I did it another way. I believe it won’t overload in the future when there will be more users.
I will try to explain it, but if anyone will need help with the code I’m willing to help.
In the “send_message.php” file, after database insert, I added a piece of code that creates a new empty text file with receiving user id as a name.
In the “receive_user.php” file, after database update (message read), I also added a piece of code, but this one deletes that same text file from above.
Finally, the PHP code used by AJAX checks if text file with logged in user id as filename exists. If it does, it echoes 1.
As you can see, there’s no constant database checking.
Related Posts:
- Jquery ajax to custom php file: returning blank data
- A $_POST should occur when submit form but is not?
- Live search from database table
- Ajax not updating to database
- How can I fetch loop of post titles via AJAX?
- Retrieve POST data from AJAX call
- WordPress Ajax always returns a 404 error
- problem with ajax and the path to the php page
- How to use wp_localize_script in a WordPress page other than functions.php?
- simple wordpress ajax plugin not working when not logged in
- Load custom field value into div with AJAX
- Update WordPress Custom Field with AJAX on cached page
- Targeting single page with JS
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Use ajax to update_post_meta
- Click loads template via ajax
- AJAX in WordPress, sending coords data to MySQL and show after into map
- How to retrieve the content (with a specific ID) via ajax by clicking a link tag
- How to speed up admin-ajax.php in wordpress
- Returning a value from a PHP page
- Sending jsPDF documents to the server
- Ajax $wpdb not returning table data
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- How to test nonce with AJAX – Plugin development
- Woocommerce add to cart quantity buttons with AJAX
- class click counter save number
- AJAX request status 200 but no actual “response”
- Ajax load more posts with multiple tax query
- WordPress Sending data to Ajax with select option
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- AJAX pagination, update current page
- Save Search System
- adjust section according to country?
- populate form fields in a loop with ajax
- dynamic dependent select dropdown
- Change “add to cart” button color based on Woocommerce product category [closed]
- Ajax request returns ‘Array’. How to output the actual results?
- Show success or error messages in Ajax response to WordPress custom registration form
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Plugins not working on AJAX requests
- Fancybox type popup window that’s not an iframe
- How to disable controls in theme customizer?
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- How do I Import / Upload Files with jQuery AJAX?
- Pull GetOption() variable into jQuery dynamically created html
- Unset session variable on page reload / setup but exclude AJAX
- Function won’t run onclick using Ajax
- WordPress plugin admin page – using WordPress function in linked php file
- jQuery Ajax PHP function call returning [object Object]
- Shortcode to pull posts
- Ajax search shows all results when user empties input?
- Why i can’t get custom fields value or post ID via Ajax?
- Get uploaded image and attach it to the new post
- Admin-ajax php not working on new wordpress version
- Add a counter for mouseovers (custom field)
- Accessing an API with jQuery and AJAX
- what does $options = get_option(‘test_theme’); do?
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- How to load previous or next attachment with jquery ?
- How to set variables with AJAX request to use in another function in WordPress
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) through wp_admin_ajax.php
- Ajax result show in console if is called outside function and not showing in array
- Ajax filter with loadmore button
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- How to change PHP variables with AJAX request in WordPress
- Update $wpdb query with AJAX
- wp_ajax_ 400 Bad Request
- AJAX to add to cart multiple products woocommerce
- update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
- How can i send id of the currently posted form data through json response in custom wordpress plugin?
- Cannot successfully execute AJAX script to call function.php specific function. Using XAMPP localhost to test
- autocomplete in wordpress using ajax with json-data
- WordPress ajax filter returning all posts when it should be filtering by category
- Input field duplicates on form submit by jQuery
- How to echo a PHP code into WooCommerce variation product?
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- How to call a function from functions.php with ajax?
- Remove item from post_meta array via AJAX
- Prepared DB Query from _POST array
- Find the method which AJAX GET calls
- AJAX Filter WHILE Loop not working WordPress
- wordpress ajax pagination
- WordPress AJAX load post metadata in modal
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- ajax form with multiple submit buttons and values
- How to run ajax in WordPress Post?
- 500 (Internal Server Error) of external php file
- Adding instant search to wordpress page
- Add php function into .js file (for tinyMCE button)
- Dynamic Gallery
- ajax form function error
- Jquery autosave text area after typing
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- notify users when changed database
- getJSON response to PHP
- Upload multiple files via ajax from an HTML file input