I have an ajaxfunction that fetches information from a server. It calls a <div> where there's some PHP and PHP-functions and there are other javascript functions inside but they don't work when I call the Ajax function.
I get the feeling the ajax misses the definitions of the javascript functions (not the call to the functions) as the definitions are not included in the PHP, but when I wrote a <HTML><HEAD> with the javascript function definitions inside it didn't work anyway.
In my main index page I have this line with the div-tag which is called by the ajax-function:
<div id="replace"><b><?php include "phpfunctions.php" ?></b></div>
You're only posting bits and pieces of your code instead of all of it.
The problem might be in the writeWimpyButton function or it could be somewhere else in your code. Without seeing all your code I can't tell. Hopefully someone will come along to help you.
Thanks, but I don't think the entire code is needed. It's all about the ajax missing the javascript code and that is the issue that has to be solved. Here's from another forum:
"when you 'load' JavaScript-code with ajax then you have to eval() it explicitly since this is not similar to a 'normal' page-load and the code isn't evaled and you cannot use it."
So from a starting point it's more about getting the ajax to evalute the javascript code that is inside the PHP.
Scripts are not automatically parsed when using innerHTML (though event based javascript will work just fine such as inline onclick attributes). You can loop through to find the <script> tags and eval them if you wish. This may work but poses a potential security issue and this is usually evidence of the need for a slight re-architecture of the solution.
What kind of "player button"? As I said before appended onclick attributes work just fine when calling functions that have already been loaded. What exactly does your "player button" do?
Perhaps a JSON version would be more appropriate then? Your PHP could send back some contents and the $row['producturl'] and your javascript can execute the function call. Is that the only thing returned by the AJAX call?
Perhaps it should be mentioned that the CSS-popup done in javascript (rel="gb_page_center[500, 500]") stopped working as well when ajax was implemented.
Below is the entire wimpy_button.js. At the very bottom of the function writeWimpyButton() (at the bottom of the page) there are two lines of document.write() but one of them is commented behind //.
// OPTIONS:
// When a button is clicked, the other buttons will stop playing.
// This option sets the state that the other buttons will go into.
// The following (default) will put the other buttons into the "pause" state.
// If the button is clicked again, the track will continue where it left off.
// var wimpyButtonRewindOrPause = "pause";
// The following will put the other buttons will stop and rewind.
// If the button is clicked again, the track will start from the beginning.
var wimpyButtonRewindOrPause = "pause";
Because you are planning to use document.write in that way you cannot just execute it from AJAX. You'll need to embed your flash in another way (may I recommend swfobject). Alternatives include splitting out the flash code using the PHP and returning the whole bit in the ajax (you can pass the needed variables from the javascript so the PHP will know what to put) or coming up with another way to embed the flash after placing the new content into your container.
Bookmarks