Calling AJAX function from within PHP
Posted: Tue Mar 30, 2010 7:02 am
Hi,
I'm having problems calling a JavaScript from within a PHP app. I'm developing this small system that has a menu on the left and a box where PHP content is outputted according to the option selected. Here's the code for my main page (just in case you can't imagine it):
The redirect function I call there is an AJAX function that fills the div with id "contenidos" with the output from login.php. The login.php script displays a login thingy inside the right box, and calls fill again on the event onsubmit (back to login.php) but sends some parameters to itself. Then if the login is correct, login.php should call fill again to replace the contents of the box with the real stuff, but as I am only reloading a piece of the page through AJAX the head section of the page has already been echoed, and is not executed when the page is loaded. The thing is: where should I place the script tag in order for it to execute immediately?
Please let me know if I haven't made myself clear, and sorry if I went crazy on the details.
Santiago
I'm having problems calling a JavaScript from within a PHP app. I'm developing this small system that has a menu on the left and a box where PHP content is outputted according to the option selected. Here's the code for my main page (just in case you can't imagine it):
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"lang="es" xml:lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Adamantoise</title>
<?php
require_once "templates/addStyle.php"; //adds some stupid css style
?>
<script language="JavaScript" type="text/javascript" src="../js/ajax.js"></script>
</head>
<body>
<div id="menu"> <a href="javascript:fill('./login.php', 'contenidos', '', 'POST');">Login</a></div>
<div id="contenidos">
<h3>Welcome blah</h3>
</div>
</body>
</html>
Code: Select all
echo "<script type=text/javascript>redirect('./menu.php', 'contenido', '', 'POST');</script>";Please let me know if I haven't made myself clear, and sorry if I went crazy on the details.
Santiago