-1

So I have a PHP file on my server which handles callbacks from external sites. There is no HTML/CSS files, just the PHP file.

Now I have to run some javaScript Code inside the PHP file but the javaScript Code is dependent on an external js file which I have access to both by file and url.

How can I link this external file to my PHP so I can use it. I've tried a lot of things but none of those seem to work.

For simplicity here's the dummy code:

<?php
echo '<script type="text/javascript">

        Parse.initialize("ID1", "ID2");");

        var TestObject = Parse.Object.extend("Class");
        var testObject = new TestObject();
        testObject.save({Text: "Hi"}, {
            success: function(object) {
                alert("done");
            },
            error: function(model, error) {
                alert("error");
            }
        });
</script>';
?>

And it's dependent on parse.js which I have in my rootfolder and also can be accessed via http://www.parsecdn.com/js/parse-1.4.2.min.js

iitum studant
  • 856
  • 2
  • 8
  • 24

3 Answers3

4

in the echo, before the tags, add:

<script src="*link to the script*"></script>

EDIT (You provided the link, so Ill do it for you):

<?php
echo '
         <script src='http://www.parsecdn.com/js/parse-1.4.2.min.js'></script>
        <script type="text/javascript">

        Parse.initialize("ID1", "ID2");");

        var TestObject = Parse.Object.extend("Class");
        var testObject = new TestObject();
        testObject.save({Text: "Hi"}, {
            success: function(object) {
                alert("done");
            },
            error: function(model, error) {
                alert("error");
            }
        });
</script>';
?>
Ashley Wrench
  • 969
  • 8
  • 25
0
<?php
    // PHP code goes here
?>

Include javascript external file :

<script src="path_to_js_script"></script>

Your JS code

        Parse.initialize("ID1", "ID2");");

        var TestObject = Parse.Object.extend("Class");
        var testObject = new TestObject();
        testObject.save({Text: "Hi"}, {
            success: function(object) {
                alert("done");
            },
            error: function(model, error) {
                alert("error");
            }
        });
</script>
Praveen Dabral
  • 2,449
  • 4
  • 32
  • 46
0

You could load your .js include from within your javascript code. This answer might be of help: https://stackoverflow.com/a/950146/261350

Community
  • 1
  • 1
Juan
  • 1,428
  • 2
  • 22
  • 30