rewrite the question:

Generated Page chat on php, it is derived form a certain number of messages, you need to remember how many messages have been in the database at the time of its generation on the server, this page has a js file, you need every second to perform an ajax request to the server and check the current number messages in the database, respectively, if it will be different from the amount that would generate a page, we will update this page. To display the new messages.

I ask to help write an ajax request to correct js (Jquery). As well as in the generation of the page pass a value to php, variable js.

File main.js:

var fn= function () {
            //Wrong ajax request
            let id_product= 321;
            let qty_product= 2;
            $.ajax ({
                URL: "Check.php",
                //Datatype: "json", //To use JSON the format of the data obtained
                Method: "Get", //What to use the POST method, change this string to post
                data: { "id_product": id_product, "qty_product": qty_product},
                    SUCCESS: FUNCTION (DATA) {
                    console.log (data); //Return the data output in the console
            IfMess >
 PrevMess) {
                window.location.reload (); //Refresh page
            setTimeout (arguments.callee, 1000);
        setTimeout (fn, 1000); 

Ready check.php code:

? php.
require 'db.php'; //Connect file database management
$ Colh= R :: count ( 'messages'); //We get the number of messages in
echo $ colh; //Send back
? ≫

phpfaq.ru/newbie/na_tanke study when and where PHP and JS are performed

Alexey Ten2021-09-07 05:03:08

Why is Return?! Well, it is impossible to understand so much where you have RNR and where is the browser! Are you always that in the browser withdraw data from the RNR via Return, this is serious?

Ипатьев2021-09-07 05:03:08

Well, the query code itself is some strange. Why can't you take a normal example of Ajax query and change to yourself? Here is another sacrifice on YouTube, who was told what to do the site can not be programmed at all.

Ипатьев2021-09-07 05:03:08

This is my first back to PHP, and he is ready for 88%, but I know a lot of crutches, but this is a competitive project in high school. Why not?

Денис2021-09-07 05:03:08

I wrote, just for me to throw off the normal example of Ajax request, Plis

Денис2021-09-07 05:03:08

Regarding where PHP and JS, the fact is that I greatly recognized recognized, and did not think about the pen, how to notify individual users when a message comes, and that is why I'm doing this, such a crutch, and Return As I wanted to show what exactly it is necessary do as an understanding of ajax zero

Денис2021-09-07 05:03:08