PHP trigger from webpage A to load content from database on webpage B

Kobbe

I am building a chat and all works fine.

When person A types a message in a textarea and clicks the SEND button of an HTML form, PHP sends it to the server.

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // collect textarea content
    // inserted (appended) to mySQL table.
    // collect chat content in mySQL table
    // display chat content in a <div> 
    }
?>

(I am not posting the PHP code because it's irrelevant to the problem)

Person B gets the message because of a javascript setInterval that triggers a function that grabs the chat content from the database via AJAX and then displays the chat content for person B in a div.

setInterval(refreshChat, 1000);
function refreshChat() {
    $.ajax({
        url: "http://eyesonpi.com/_/php/chat.php",
        type: "post",
        success: function(data) {
        $("#chatWindow").html(data);
        },
        error: function() {
        $("#chatWindow").prepend("Error");
        }
        });
    }

When I tried it on my iPhone, running IOS 10, the AJAX call fails. IOS 10 has a problem with AJAX. https://forums.developer.apple.com/thread/64526

I tried with plain Javascript (xmlHttpRequest) and with jQuery.

I tried the chat window of my hosting company from my iPhone and their chat works. I don't know where to begin with a workaround. How can person B get the message from person A without reloading the page? Any suggestions?

Thank you.

Nurik Nurmetov

You can try to use websockets for the chat. Or long pooling technology which allows connection to be persistent between server and client(browser or mobile app). if you choose websockets. Then you can try to use on server side: Workerman or Ratchet.Both, perfect do their job. All modern browsers natively support websocket, or you can use popular libraries like sockJS for cross-browser support.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Display info from a database on a webpage using php

Download image or webpage with image from PHP webpage

how to read content from webpage

How do I load data from a database and display it on a webpage?

Display a table on a webpage from database

How to get specific content from a webpage using curl in php?

Generating a webpage from an SQL database depending on what link was clicked (PHP)

Getting data from a webpage in PHP

php DOM read from webpage

is it Possible to Trigger Android Toast Notification from Webpage?

Headless Chrome - trigger callback from loaded webpage

How to copy/paste 'int' content from webpage

Unable to get a dynamically generated content from a webpage

Possible to dump AJAX content from webpage?

Scraping: cannot extract content from webpage

Download only the text from a webpage content in Python

Read content from rendered webpage into nodejs

Checking the content from an URL: Is it a file or webpage?

Scrapy is returning content from a different webpage

Webscraping content from a webpage not using selenium

Fetch data from database and update webpage continuously

Clearing table in database when exit from webpage

images not loading on webpage from database using django

Accessing SQLite3 database from webpage

Load Content from SharePoint Library Folder by Created Date Order on Webpage using Javascript

PHP - send msg from webpage to mobile phone

Download a file stored in CRM from a php webpage

send an email from a html webpage using php

How to get data from a table on a webpage in PHP