阿贾克斯字preSS传递数据 [英] ajax in wordpress to pass data
本文介绍了阿贾克斯字preSS传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
人,我有一个code,我需要在Word preSS包括。你能告诉我如何改变这些codeS中字preSS工作???
People, I have a code that I need to include in Wordpress. Can you please tell me how to change these codes to work in wordpress???
非字preSS code是:
Non wordpress code is:
JS
$(document).ready(function() {
$('#example').ratings(5).bind('ratingchanged', function(event, data) {
$('#example-rating').text(data.rating);
$.ajax({
url : 'rating_plugin.php',
type : 'POST',
data : { rating : data.rating },
success : function(response){
console.log("successfull");
}
});
});
});
PHP
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
echo $_POST['rating']'
}
感谢。
推荐答案
在字preSS一般它能够更好地使用内置的AJAX功能来与字preSS
In wordpress in general its better to use the built in ajax functions that come with wordpress
因此额定添加到您的functions.php (这是在这些线路上)
so add the rating to your functions.php (something on these lines)
function rateAjax()
{
require( get_template_directory() . '/rating_plugin.php' );
}
add_action('wp_ajax_nopriv_PostAjax', 'rateAjax');
add_action('wp_ajax_PostAjax', 'rateAjax');
jQuery的:
Jquery:
$(document).ready(function() {
$('#example').ratings(5).bind('ratingchanged', function(event, data) {
$('#example-rating').text(data.rating);
$.ajax({
url : '<?php echo admin_url('admin-ajax.php');?>',
type : 'POST',
data: { action : 'PostAjax', rating : data.rating },
success : function(response){
console.log("successfull");
}
});
});
});
这篇关于阿贾克斯字preSS传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文