Jump to content

How To Include PHP Function From PHP File Into Application/X-Javascript File


phpQuestioner

Recommended Posts

I have one php page with roughly 10 functions in it and I have put this page in a include in a application/x-javascript. The include works, but it only pulls the first function from the include. I want to be able to specify the function I want to pull from the include in put into a specific area of the javascript. My code is below; does any know what I mean and/or how to do this?

 

<?php

header("Content-type: application/x-javascript");

//make asc javascript function

echo "function makeascend()\n
{\n
document.getElementById('vehicles').innerHTML='";
?>
<?php
include("sort.php");
?>
<?php
echo "'\n
}\n";
?>

yeah - i tried that; like this:

 

<?php
include("sort.php");
?>
<?php

header("Content-type: application/x-javascript");

//make asc javascript function

echo "function makeascend()\n
{\n
document.getElementById('vehicles').innerHTML='myphpfunction()';\n
}\n";
?>

 

But that did not work; the php function was not included; just spit out this:

 

function makeasend()
{
document.getElementById('vehicles').innerHTML='myphpfunction()';
}

That is because it is litteraly a string. I really don't know what you are trying to do. does 'myphpfunction()' return a string that you put in the innerHTML of the element? If so, change the line from:

document.getElementById('vehicles').innerHTML='myphpfunction()';\n

 

to:

document.getElementById('vehicles').innerHTML='" . myphpfunction() . "';\n

 

If it wasn't including the function, it would give you an error when it tries to execute it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.