Sunday, July 29, 2012

javascript – How to include a file OR PHP code with JS?



How can I include code, for example using Javascript? Or if that can\’t be done, how can I include a whole PHP file?


P.S. Found some script called \”require\” or \”include,\” but I prefer two lines of code instead of a huge library (using jQuery though). If that can\’t be done, let me know, I will try to think of something else.


EDIT:


Okay, an example of what I want to do:



function foo() { if(x = 1) return 1; else return 0; }


Then if the function returns 1, I want to either add HTML/PHP code to DIV tags OR I want to include a PHP file containing that code.


EDIT #2:


What about only HTML?



document.getElementById(\'test\').innerHTML = \'<a href=\"google.com\">a cool link</a>\';


That doesn\’t seem to work either.


I have an empty div tag with id=\”test\” in my code.






Rating: 4 out of 5 based on 3 ratings



The post javascript – How to include a file OR PHP code with JS? appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/javascript-how-to-include-a-file-or-php-code-with-js.html

No comments:

Post a Comment