Below is the code i'm using. When ever i use to return some value , it's returning as -1. Please tell me where i made the mistake or guide me what's the pbm in the code!
Javascript:
$j = jQuery.noConflict();
$j.ajax({
url:"<?php echo admin_url( 'admin-a开发者_C百科jax.php' ); ?>",
type:"POST",
data:"action=market_place_youtube_validator&id="+code,
success:function(data){$j("#loading").hide();$j("#mine").append(data);}
});
PHP (admin-ajax.php):
function market_place_youtube_validator()
{
echo "Yes Youtube is right";
}
You are using PHP (echo "Yes Youtube is right";
) within javascript. To return a value you would need to do return "Yes Youtube is right";
Do you have this in your functions.php?
add_action('wp_ajax_nopriv_market_place_youtube_validator', 'youtube_validator');
Where wp_ajax_nopriv_[your action parameter name]
$j = jQuery.noConflict();
$j.ajax({
url:"<?php echo admin_url( 'admin-ajax.php' ); ?>",
type:"POST",
data:"action=market_place_youtube_validator&id="+code,
success:function(data){$j("#loading").hide();$j("#mine").append(data);}
});
function youtube_validator()
{
echo "Yes Youtube is right";
}
I think you have to call die or exit after the output is being echo to the browser to prevent returning value -1
精彩评论