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
- Do I require the use of nonce?
- Real time Duplicate title check
- Load custom field value into div with AJAX
- Security – Ajax and Nonce use [closed]
- Looking for a better way to handle an ajax script that pulls in post data on click
- Can’t use get_results() in ajax query
- Use ajax to update_post_meta
- Problem with WordPress Ajax form
- Display notification only once
- Access/update database with jQuery
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Passing jQuery value using Ajax to a page template
- ajax_object is not defined when ajax calls the function
- Why is this Ajax not working?
- Stumped – Ajax Response Returns 0
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- Use ajax from function.php
- Ajax return code 400
- doing an ajax request always outputs 0
- How to test nonce with AJAX – Plugin development
- Woocommerce add to cart quantity buttons with AJAX
- class click counter save number
- wordpress count link clicks by ip address
- ajax, right way to do it and make it works?
- WordPress ajax doesn’t display object method on jQuery .change() function
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Ajax date_query not working past the first iteration
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- AJAX pagination, update current page
- adjust section according to country?
- How to add a do_action on refreshing of WP customizer?
- Refresh table data with Ajax
- Setting value of session with Ajax not working
- [jQuery]Adding shortcode
- Display parent and child taxonomies in separate drop down select fields
- 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
- Proper way to use WordPress function with AJAX PHP file
- Add a counter for mouseovers (custom field)
- Accessing an API with jQuery and AJAX
- 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
- Search Ajax Call – Use Form Data in Response
- Why does PHP called with Jquery AJAX not allow additional php code to be added?
- 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
- Database entry removed on browser refresh, Ajax PHP jQuery
- 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
- Can’t make lazy load for my site, help!
- 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)
- 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?
- Custom theme admin-ajax.php 400 (Bad Request)
- number of posts with “Load More”
- Prepared DB Query from _POST array
- Find the method which AJAX GET calls
- AJAX Filter WHILE Loop not working WordPress
- 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?
- Adding instant search to wordpress page
- Add php function into .js file (for tinyMCE button)
- ajax form function error
- Load Meta box value into div AJAX [duplicate]
- notify users when changed database
- getJSON response to PHP
- ajax problems on loading page [closed]
- Help with AJAX request
- I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)
- custom AJAX filtering logic and outputting results into an Elementor Loop Grid widget
- Trying to GET data with ajax from database and show in fullcalendar