form in dynamically loaded page doesnt work anymore

I have two pages, called “messages.php” and “messages_inside.php”.

The page “messages.php” contains a div (with ID “messages_inside”) that is loaded dynamically, using this piece of code:

[php][/php]

I need this script so every 5 minutes (300000 ms) the div will be refreshed. I’ve a form on the page “message_inside.php”, which works properly if I visit the page directly. But if I visit the page “messages.php” and I use the same form from this page, it doesn’t work anymore. Why?

Hmmmm, it looks like it should work, but, try this instead:

[php]

This routine seems to work for others. I think your error is something in the extra call of the auto_refresh routine… But, not sure why!

Let us know if this works for you…
[/php]

Hold on… I just noticed you declare the variable that holds the call to the routine after you set it up, but, you do not have it actually being called after the first time. Not sure on the flow of your routine… Try the one that I found and let us know…

Thanks for the reply. I wasn’t home for a couple of days, sorry for the late answer. The code you’ve submitted was my original code. But I got the problem that the pages took 300000 ms (the value inside the function) to display the content at the first time of the page load. By adding this extra call I avoid this problem, so the text is printed directly on the page after the page is opened.

Well, you can’t load the auto-refresh without parms.

I would just load the PHP manually when the page loads and let the auto-refresh do the updates.
So, just manually add in an “include” in the PHP file for that DIV.

What that will do is manully load the included PHP file and still auto-refresh after the page loads.

Should work for you!

Yep, exactly what I was just doing… Didn’t get the code to work, so I’ll go for the easiest way. Thanks for the reply!

Many more errors appeared as I tested the whole page… Too many problems… ???

Well, I would guess without seeing the code that it is because you left all the headers in
the file. You can’t load the included file using Jquery without the headers and then load it
in an include with the headers. Did that make sense?

Nope, all the headers are on both pages.

If I open the included file straight away on the internet everything works just fine, the way it should. But this all stops as soon as it is loaded from the other page using the include.

What I’m basically trying to achieve:

I have a page messages.php which has a div filled with messages.

Just this div needs to be refreshed every 5 minutes, all other elements on the page doesn’t. So just the DIV. I tried couple of things.

I’ve tried to put
[php][/php]
on top of a page called messages_inside.php and load this page on messages.php using
[php]<?php include 'messages_inside.php';?>[/php]

but this still makes it refresh the whole page, all elements and not just the div.

I’ve also tried
[php][/php]

and put an empty div on the page
[php]

[/php]

this loads the page correctly, but it takes 3000 ms before it displays the messages (so it waits 'till it’s refreshed for the first time and than all messages are shown).

I can avoid this by putting in the same
[php]<?php include 'messages_inside.php';?>[/php]

inside this div, so it will look like

[php]

<?php include 'messages_inside.php';?>
[/php]

this offers a solution for the displaying error (so it is visible at the first time and keeps refreshing) but this kills some functions on the messages_inside.php

So,

what IS the easiest way to refresh just a div and not the whole page. It doesn’t matter if the messages are on the same page (directly in the div) or will be loaded using an include code. One page, two pages, doesn’t matter, as long as just the messages are refreshed every 5 minutes and all other elements stay untouched.

I tried multiple options, all doesn’t offer me the way I want it to.

You have it correct… So, I guess I didn’t explain it correctly…

The first page can not be loaded with headers. You would have to add it inside the DIV
manually. just the parts between and So, no Doctype’s or 's or

's and not 's. The rest is okay.

You can not have two pages loaded on one page. The JQuery strips out the headers when it
loads an external file. So, strip out code between your and place it where
you have the original INLCUDE. Between the

In that way, it loads the page correctly the first time. Then, the JQUERY will reload it as needed.

There is another way… You can have two values in your JQuery routine. Use a variable and alter
it as needed. So, leave the page working as-is with the 300000 ms count. But, place that value in
a variable. Set the variable during page-load to 0.

In your load routine, if it is set to 0, set it to 300000. In that way, the first time it will load right away
and from then on after the count down. Did that make sense? Should work better that way, I think.
And, this way, you do not have to deal with multiple copies, with/without headers…

(Sorry I did not think of that before…)

Oh, by the way, to set a variable on startup, it is something like this:

$(‘document’).ready(function(){
var counter_variable=0;
});

Something like that… Let me know if that works…

it kinda works… But I have a form on the message_inside.php which doesn’t work anymore. It still works if I open the page directly in my browser, but if it’s loaded using the php include tag all form action stops working…

LOL, this one keeps going on and on… So, I researched this a bit and it seems to be a common problem. I guess you can easily load PHP pages into DIV’s. BUT, since the page loads BEFORE the added-in page, the form system breaks down.

Seems that the solution is to change the submit button on the added in page to be sent by JS or JQuery.
(Something to do with headers and forms from what I saw…)

Here is a link where someone solved it on their page. Hope this helps…
http://stackoverflow.com/questions/15598194/jquery-form-submit-does-not-work-after-using-a-load-function
Let us know…

Another thought on this new problem. Is the page that loads inside loaded because of
dynamic text only? I mean does the form itself change over time? Perhaps you can hard-code
the form, but, just load the text. This won’t work of course if you need dynamic form fields…

Just a thought…

Thanks for your help but forget it… ??? You saw my demo page when I sent you the link a couple of days ago, the messageboard, remember? It has a function to delete messages, using a href function which is linked to a script that opens a modal window. This function stops working too as soon as it’s loaded inside the page…

I thought it would be lot easier to create such a simple function, but this small changes brings a lot of headache… Anyway, thanks for your help… :wink:

Perhaps I am confused on what you are trying to do.

All of this thread was about dynamically loading a page or auto-refreshing.
It was not about modal forms or deleting records or messages.

Deleting should be handled using a with a direct PHP file not a dynamic one.
Why would you use an auto-refreshed a routine that would delete items?
Usually auto-refreshed pages are used for checking for new messages or
displaying message logs not deleting items.

My mistake, sorry. I’ll try to explain it.

This page shows a list of message, as you saw on the demo page I’ve sent you. This page does need to be refreshed every X amount of time, in order to keep the messages updatet. But, messages should be able to be deleted, once they’re old. Right now, this is possible by clicking the message you want to delete. After clicking it, a modal window opens, showing the contents of the message once more, followed by a delete button.

[php]

[/php]

On this deleteMSG.php page a simple script deletes the record from the database and returns to the page with the messages.

This modal window is a

, which is triggered when someone clicks on a photo, right before the text of the message, using a trigger.

If I use on top of the page, everything works just fine. The page is reloaded, the modal window works as it should, no problems so far. But if I use a script to load the message on the page (as written in the previous comments here), the to trigger the modal window stops working. It does nothing. The page just jumps back to the top of the page because of the #, but that’s it. It doesn’t reach the modal window.

Well, as far as I can come up with it is a problem with PHP being a modal. First, PHP is server-side only.
Therefore, if you have a page already loaded, there is no PHP on it. It is then just HTML and Javascript.
If you call a PHP file outside of the currently loaded page, the page itself does not understand anything
about the processes done on the server. It only knows about it’s own status. Therefore, nothing can
change on the current page unless you refresh the page.

To refresh the page, you can do it two ways.

First, use a meta-refresh which basically just reloads the entire page and uses whatever PHP code that
is in it server-side. (In effect refreshes the data as it actually redraws your items.)

Or, the second would be to use Javascript or JQuery to handle the refresh. You can just execute a page
refresh after an item is deleted using a JS command like: location.reload(true) Forces it to reload the
current page from the server. (This would save reloads as it would only be done when you deleted an
item not every so many seconds…)

I think the second way is better for you so the page does not keep refreshing and tying up the server
every so many seconds…

Hope this idea helps you! Let us know…

Sponsor our Newsletter | Privacy Policy | Terms of Service