Ok so I am trying to echo an function from jQuery inside of PHP.
I was searching a little bit, I did not found any exact answer but I found that I need to use ajax for it ?
I am not familiar with ajax so I have found this.
<?php
$status = "<script>
$.ajax({
url: '/',
data: {action: 'test'},
type: 'post',
success: function(output) {
notifyBox();
}
});
</script>";
?>
I also have this part somewhere on the page:
<?php if(isset($status)) { echo $status; } ?>
I am not quite sure if I need all of that to execute the function ?
But it works only if I put jQuery in head of the website.
I usually put all my scripts above </body> (at closing tag) and now it bothers me if I have to put all these scripts into head
Because of many pages I cannot separate all scripts now just cause of one page that bother me at the moment.
Can anyone please tell me, how do I call that function without getting console error of undefined ‘$’ because jQuery is loaded at the end of the page.
Thank you in advance.
That should work so long as you make sure that you put your PHP
ifstatement after the<script>tag that includes jQuery.