Is it possible to add php to a jquery function? On ajax success I’m displaying some text in a div using 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
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.