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 .4.2.min.js
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./js/parse-1.4.2.min.js
Share Improve this question asked May 7, 2015 at 12:02 iitum studantiitum studant 8663 gold badges9 silver badges25 bronze badges 2-
Do you even have
<script type="text/javascript" src="/parse-1.4.2.min.js"></script>
in your PHP ? – Coloco Commented May 7, 2015 at 12:06 -
2
By the way you can close and reopen
<?php ?>
tags so I don't think you need to echo there – Coloco Commented May 7, 2015 at 12:07
3 Answers
Reset to default 4in 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./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>';
?>
<?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>
You could load your .js include from within your javascript code. This answer might be of help: https://stackoverflow./a/950146/261350