How to update web page content like facebook news feed update [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am trying to create a web page that can update data automatically calling ajax method. But ajax method need to call by user. There is no process that can always try to find any update of this web page. I want to update data like chat box when Data update on my server. Now I notice that Facebook news feed automatic update. I want to make like this.

Ajax methods don't need to be called by the user; you're free to call them whenever you like from your Javascript code.
One simple possibility would be to make use of Javascript's setTimeout() or setInterval() functions which can run whatever Javascript you like (including Ajax calls) after a set time interval.
Alternatively then you could look at newer technology like WebSockets https://en.wikipedia.org/wiki/WebSocket to help reduce load on the server and browser.

Use setInterval
window.setInterval(function() {
... ajax call ....
}, 2000);
call ajax function automatically

Related

Scraping data which loaded after scrolling to bottom [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm working with PHP and I want to scrape some data from any website. But I have a problem. I scrape data but these items number are 48. But I know that page has 11K items. Rest of datas extend when you scroll and you get new bunch of datas (48 items).
I'm scraping with simple_html_dom. How can I manipulate scroll and get data ?
Thanks! :)
Sounds like the missing data is loaded via ajax.
Check the Network tab in the Developer Console (by pressing F12). Take a look at the URL which is being called (and the response), and edit it to your needs. Then call this URL instead of the one you are taking now.
It is impossible by this way.
But if you need to scrap this data you can send requests to endpoints which return lazily loaded data. You must research js code of target site.
p.s.
If you want to use really hard approach, you can research browser emulating.

Efficiently output query result with jQuery .ajax()? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Sorry in advance if what I am going to ask is silly, I am having trouble understanding the asynchronous HTTP responses. I am trying to use jQuery .ajax() with PHP and MySQL in the following context:
when page loads I will query and return all the applications for a particular id, and then I will use a while loop to output them;
also there is a button that allows the user to add new application for that particular id -> on click it:
shows a hidden form and gets the values in the inputs;
sends the data to PHP using the .ajax() method;
performs the insert.
and I am stuck at this point
I need to output the newly added application above the existing ones, but the query and while will do it only when an synchronous HTTP request is sent.
I tried to use the .success() but the HTML I need to output inside is really long and I am afraid it will be hard to maintain having outputs from both PHP while loop and jQuery.
Can you please help me understand an efficient way to do this? I have never dealt with asynchronous HTTP request before. Also, I am can't use any JavaScript templating libraries.
I would really appreciate your help!
An ajax postback typically implies some sort of JSON-based web api behind it. Examples of this on the internet abound.
https://www.lennu.net/jquery-ajax-example-with-json-response/
http://www.9lessons.info/2012/05/create-restful-services-api-in-php.html
Your REST endpoint should return the minimal amount of JSON data you need. At which point you can use that data to update/bind to elements in your DOM inside your "done" or "success" callback.

Can we Use php script in Google Tag Manager [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Just wondering if a php code could be executed via Google Tag manager?
Thanks
No. The Google Tag Manager inserts client-side Javascript. PHP requires a server that is configured for PHP. Inserting a PHP script via GTM would just output the raw PHP code to the browser, it would not execute the code.
If you want to include the results of a PHP Script you would have to run the script on your own server and fetch the results via Javascript as suggested in UncleRicos answer.
I would look at Custom Events in Triggers here: https://support.google.com/tagmanager/answer/6106961?hl=en&ref_topic=3441647&vid=1-635797415927700239-1991783559
You can specify a javascript event that would be called upon a trigger being executed, which in turn could call a routine via ajax (which could be PHP or anything).

How to do a real-time dashboard with charting [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to create a dashboard for a bespoke web service we have so that we can monitor usage on a real-time basis. Something similar to the couchbase dashboard if you have seen that. If not, its basically a line graph that scrolls right to left with time along the bottom of the graph and usage on the y-axis.
To minimise data bandwidth I am assuming there is a way to pass just the changed data to update a graph rather than sending a new image/vector each time. And this would get drawn with a javascript charting library.
What I am unclear on is how to get the data from the server. Is the normal approach to have the javascript code poll the server using AJAX every second (if you are after second by second updates) or is some other method used?
I used PHP for the back end and HTML/JS for the client end.
And does anyone have any examples or links that could be helpful.
For getting the data from the backend, I think you can call it using Ajax, reload each second using setInterval(), making something looks like:
setInterval(function() {
$.ajax({
url: url of your backend server,
type: 'GET',
success: function (data) {
//data returned from the server, use it to draw your chart
}
});
}, 1000); // recall ajax every second

Ajax for DB Updation [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am updating 100,000 records. So the page looks blank while the update query process runs on the backend. Can someone tell me how to display the text "Please wait blah blah" until the update ends?
Well depending on your script and the structure, the easiest way would be to change a div's css property called display. When a user clicks on a link that starts the php script, you could add a javascript code like :
$(#+THEIDOFYOURDIV).show("slow");
});
and once its done, you can call another js function to close it like :
$(#+THEIDOFYOURDIV).hide("slow");
});
*NOTE I am using jquery functions, so you would need to include jquery in your pages.
There is another way you could do this using php ONLY, I had the same issue so take a look at this: how to show results while a php script is still running

Categories