usually can php variables different php file declared this:
$myvar = 'hello'; require 'header.php'
so in header.php can use $myvar. cannot access variable loaded ajax in jquery. example:
index.php:
<html> <body> <div id="mydiv"></div> </body> </html>
in script have:
$(#mydiv).load('newpage.php')
newpage.php :
$myloadedvar = 'loaded var';
but cannot access $myloadedvar index.php, possible or cannot access php variables created ajax ?
php server-side language while javascript client-side language. way can php data javascript outputting data in manner. if want full output, echo it. if want load bunch of simple php variables javascript, can add variables need js know array, , json_encode
them.
$firstname = 'john'; $lastname = 'doe'; $outputarray = array('firstname' => $firstname, 'lastname' => $lastname); echo json_encode($outputarray);
then when ajax function can retrieve data object , can use result.firstname
in javascript.
passing complex items impossible though, such database connections properties.
Comments
Post a Comment