2
reset.php文件:在Ajax调用WordPress的PHP函数?
<?php
add_action('admin_init','popup_template_reset_options');
function popup_template_reset_options()
{
delete_option('popup_template_on');
delete_option('popup_template_close');
delete_option('popup_template_escape');
delete_option('popup_template_external');
delete_option('popup_template_home_page');
delete_option('popup_template_all_pages');
delete_option('popup_template_template');
delete_option('popup_cookies_display_after_like');
add_option('popup_cookies_display_after_like','365');
//add_option('popup_template_on','1');
add_option('popup_template_close','1');
add_option('popup_template_escape','1');
add_option('popup_template_external','1');
add_option('popup_template_force_timer','2');
add_option('popup_template_home_page','1');
add_option('popup_template_all_pages','1');
add_option('popup_template_template','2');
}
?>
脚本的Ajax:
<script type="text/javascript">
$(document).ready(function() {
$('#reset_general').click(function()
{
$('#result1').css("display", "block");
jQuery('#result1').animate({'opacity': '1'});
});
});
function resetgeneral() {
$.ajax({type: 'POST', url: '<?php echo WP_PLUGIN_URL; ?>/fantasticpopuptemplate/inc/reset.php', success: function(response) {
//$('#fff').find('.form_result').html(response);
$('#result1').css("display", "none");
$('#resets1').css("display", "block");
$('#resets1').html("Settings Resets");
$('#resets1').fadeOut(2500, "linear");
}});
return false;
}
</script>
<form onsubmit="return resetgeneral();" id="form_general_reset" class="form-1">
<input type="submit" value="Reset" id="reset_general" name="reset" class="button-secondary"/>
<input name="action" type="hidden" value="reset" />
</form>
嗨,我试图调用Ajax中的PHP复位功能,但是当我使用Google我知道,不是直接可能性调用PHP函数,所以我把这个特殊的功能在单独的PHP文件,并调用该PHP文件我不知道我怎么能做到这一点在阿贾克斯我试过这个代码,但没有发生。出现设置重置消息。我如何做到这一点任何帮助都会很棒。在使用ajax概念之前,我使用isset
函数在php中尝试了但是它每次都会获取页面,因为只有我跳入ajax。
谢谢beerwin我只用了约1周的ajax。我读出了相应的链接。我调用php函数,当我点击重置按钮,它获得特定的功能(在使用ajax我使用isset函数之前)。我不知道如何在ajax中做到这一点,任何帮助。对不起,我有点与相应的链接混淆 –
你尝试过这种解决方案吗? – beerwin
你实际上不能直接从Ajax调用调用PHP函数。你可以做的是用Ajax发送一个变量,并在PHP文件中监听该变量,如果变量值为true,那么调用函数 – Martin