Example: I have file ajax demo_ajax.php will return:
<p>this is data in file ajax</p>
<script>
demo();
</script>
And file script demo_script.js :
$(document).ready(function(){
function demo(){
// my code here
}
});
My question is how to in file demo_ajax.php can call function demo() in file demo_script.js, I will try and get error function undefined
Change
$(document).ready(function(){
function demo(){
// my code here
}
});
To
$(document).ready(function(){
});
function demo(){
// my code here
}
Dont't forgot to include your script file on parent page
Try this...
$(document).ready(function() {
$(this).demo();
});
// You can replace 'this' with another selector such as 'p'
// Then inside the 'demo' function, $(this) will refer to your selector
$.fn.demo = function()
{
}
include your
demo_script.js
on the top of
demo_ajax.php
and then it will work..