admin管理员组文章数量:1130349
Right now I have code that looks like this:
function search_ajax_fetch() {
?>
<script type="text/javascript">
function searchFetch() {
var keyword = $('#keyword').val();
if ( keyword ) {
$('#datafetch').show();
$.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: 'post',
data: {
action: 'data_fetch',
keyword: keyword
},
success: function(data) {
$('#datafetch').html( data );
}
});
} else {
$('#datafetch').html( '' );
$('#datafetch').hide();
}
}
</script>
<?php
}
add_action( 'wp_footer', 'search_ajax_fetch' );
But I am trying to move all the jQuery to an external file, and call this function instead. But I cannot make it work by moving it to an external file and doing it like this:
function search_ajax_fetch() {
?>
<script type="text/javascript">
searchFetch();
</script>
<?php
}
add_action( 'wp_footer', 'search_ajax_fetch' );
Why isn't this working? The js file is loaded correctly!
Right now I have code that looks like this:
function search_ajax_fetch() {
?>
<script type="text/javascript">
function searchFetch() {
var keyword = $('#keyword').val();
if ( keyword ) {
$('#datafetch').show();
$.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: 'post',
data: {
action: 'data_fetch',
keyword: keyword
},
success: function(data) {
$('#datafetch').html( data );
}
});
} else {
$('#datafetch').html( '' );
$('#datafetch').hide();
}
}
</script>
<?php
}
add_action( 'wp_footer', 'search_ajax_fetch' );
But I am trying to move all the jQuery to an external file, and call this function instead. But I cannot make it work by moving it to an external file and doing it like this:
function search_ajax_fetch() {
?>
<script type="text/javascript">
searchFetch();
</script>
<?php
}
add_action( 'wp_footer', 'search_ajax_fetch' );
Why isn't this working? The js file is loaded correctly!
本文标签: javascriptCall jQuery function from PHP
版权声明:本文标题:javascript - Call jQuery function from PHP? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749204605a2332351.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论