Adding PHP to jquery function
Is it possible to add php to a jquery function? On ajax success I'm displaying some text in a div us开发者_开发技巧ing the .text()
function.
success: function(html) {
msg_each.nextAll('.msg_box:first').text('show some text...').fadeIn(200);
}
Via jquery, I would also like to use a Wordpress function:
<?php comments_popup_link('Post Comment', '1 Comment', '% Comments'); ?>
How can I add that to the .text()
function?
PHP runs on the server. JavaScript runs in the browser. You need to use Ajax (something like $.get()
to perform an HTTP get on a resource on your server. This will return (probably) HTML or plain text that you can pass into your .text()
call.
Basic skellington
success: function (html) {
$.get('url/to/page.php', function (data) {
msg_each.nextAll('.msg_box:first').text(data).fadeIn(200);
});
}
Since you're already making an Ajax call, however, you might just be able to modify the server-side page you're querying to include the additional HTML (generated by the comments_popup_link()
call) so you don't have to make an additional XHR.
精彩评论