PHP Page show user status with refresh - php

I have a PHP-Script thats queries User-Status via SOAP.
I want to refresh the Page when the status for a user changes, for example when the user makes a call or hangs up.
How can I refresh the Page fast and smooth to always show the latest user status?
I read about Ajax and searched for a solution in HTML5. What is your advise?
Thanks for any helpful post :-)

My advice is to not load and interpret soap before page load.
Make two pages.
1 content page that displays everything you want, without the "latest status"
When the content page is loaded, make an ajax request to the 2nd page.(jQuery example)
$(document).ready(function(){
$.ajax("lateststatus.php").done(function(data){
// Change the name of the element to the element where you want to display the data
document.getElementById("mycontentdiv").innerHTML = data;
});
});
Then in the 2nd php file(lateststatus.php) load the soap file, interpret and generate only the html code you want to display in the content div.
That's it in a nutshell.

Related

Search in a modal, update DIV on original page

It's another late night and another seemingly simple issue that's causing a headache!
So, here's the situation. I have a simple HTML form that's in a Bootstrap modal. When this form is submitted, there's an AJAX POST to a receiving page, SESSIONS are set and the request is then forwarded to a simple DB query. This all works.
What I want to do is show the sessions on the original page without a page refresh.
I thought this would be easy so I tried using this on the original page;
$('#filteroptions').on('hidden.bs.modal', function () {
$("#breadcrumbs").load('includes/files/private/breadcrumb.php');
});
breadcrumb.php holds the output format and the file is populated immediately after the POST from the modal (called filteroptions)
I also tried to attach it to the POST success with a simple success process to load the file but each time, the breadcrumb.php fils to be loaded.
Curiously, if I ctrl+F5 the page after the first POST, there is no value shown BUT if I search again the DIV is updated each time I search after that.
Why would the request not fire the first time that the search is performed? Why do I need to refresh the page for everything to start working?
There is no caching to it's not a case of a dependantr file being cached after the refresh.
Thanks
The solution was to populate the div with nothing and then update it.
Previously, the div was only being drawn when it was populated thanks to the code in the breadcrumb file looking for a specific POST or SESSION variable.
It now allows for a blank value.

JQuery - Dynamically Changing Pages

This is kind of hard to explain but i'll do my best to explain it and maybe someone knows what i'm trying to do.
I have a dashboard.php page and within that page i have a main-interface div that covers 100% width underneath a nav a header.
This dashboard when the user clicks a link changes the content of main-interface div with data from another page for instance search user.
I can load the search user page into the main interface fine but the problem I have is when I click search user it takes me back to the dashboard.php page with the original main-interface content rather than a table of all the users I searched.
I am having trouble telling the jquery that I want it to search for users and populate it back into the main interface page after the search user link was clicked.
Hope some one gets the idea of what im doing and trying to accomplish.
You could split tasks into client tasks and server tasks.
Client tasks are things that javascript/jQuery will do on the browser.
And server tasks are things that your server will do when requests get in.
This does not mean that the server will need to create full html pages, just send some information to the client bypassing a full page creation.
I often do something like:
<script>
var send = { };
send[ 'find' ] = $("input[name='find']").val();
send[ 'token' ] = $("input[name='token']").val();
$.post( 'request.php', send, function( data ) {
$("#name").html( data );
});
</script>
There are some options on the data you will get from the request.php.
You can let request.php create html that you can put into a <div id="name">.
Or write client side code that creates HTML from JSON.
Hope it makes sense.

How to reload a webpage after a specific time without refresh the page(address bar will not be refresh) by jquery/ajax

It will be implemented in PHP. Now it is implemented by the following way.
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);",timeoutPeriod);
}
Now it refreshed the addres bar...but I don't want to refresh the address bar.....
if you want to reload the page , the whole url will be reloaded, you can't do anything about that
but if you want to reload some specific location of the webpage which is getting data form database
then you can by just calling jquery ajax which will get updated data from database.
this technique is used by many websites to update the time of post or comment

Scroll text down after clicking

I am having difficulties in the following problem:
I have a screen in PHP which displays a list of some records when I choose any of these
records (by clicking) it gives me a web site to share the data with this record. So far, it works.
I need to click on some of these records, instead of him
open another page, scroll down the screen and the record data to appear in the same screen, ie without opening another window.
Do you have any idea how to do this?
Thanks
You'll need to have a DIV at the bottom of the page, which will be completed by using an Ajax call and some javascript or jquery.
Without going into too much detail, heres what needs to happen:
User clicks a link which fires off an ajax request.
The backend PHP script takes the ajax call and generates either XML or pure HTML and returns the data.
JQuery or JavaScript on the original page takes the return and populates the empty DIV at the bottom of the page.
Regards
It sounds like you'll need to use ajax to pull this off.
I would personally suggest starting with reading up on the jQuery javascript library if you are not familiar with it already. It provides a very good set of ajax tools to work with.
Create a DIV layer on the bottom of the page. Use a simple AJAX library like this
Create a new php page that will only load a new record based on the recordID and call this page on the onclick method of your link that is now opening in the new window
I would try adding some jQuery to your page to handle this effect.
If you do add jQuery here is a function written to do just that:
http://pastebin.com/SeMHwSgg
Call the script like so:
Where a is the record you are having them click on and href="[some anchor]" located at the spot on the screen where you want the scrolling to stop:
<a id="gotop" href="#" onclick="goTop();return false;">click here</a>
So
Indeed, there is no error, it just does not have the effect that (scroll down the screen and show the record data). For now, it only shows the record open in another window.

jquery dynamic pagination for comments

I would like to create a pagination system for comments in my website.So far, I have been able to create pagination using php/mysql and html but the page has to refresh every time we click on the next button(for the next set of comments) or previous or a particular page....
As far as my knowledge of jquery is concerned I am thinking that, when the user clicks on the next button we post data for the page number to comments.php then echo all the comments in comments.php, then the jquery data variable recieves all the data echo'd in the file and appends it to the #comments box...
Is my solution a valid one??? or anyone has a better solution.....thanks
Your question doesn't make much sense and is very jumbled.
You can either load the entire list when the page first loads, and use jquery to paginate it by hiding the extra entries, which will work fine for lists with a few pages worth of content.
The other option is to use AJAX to fetch the next or previous page when the appropriate link is clicked.
There are plenty of pagination add ons for jquery. Maybe check them out.
Don't use a POST request to get the next page as it looks like you might be, unless you are just using the wrong terminology.
Yes, when you click 'next', you send ajax request to comments.php and replace current comments with new ones.
You can do it with a get()/getJSON() call in jQuery.
Something like
$('#next').click(function(){
$.getJSON('url?withnextpage=number',
function(data){
//update variables or the DOM
});
});
Returning it in JSON may be quicker. I hope that helps

Categories