Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.