我创建了一个wordpress插件,以允许我的客户创建具有rsvp功能并为事件付费的事件.我对某些代码需要放置在何处以及如何向插件文件夹函数文件中的函数提交表单感到困惑.
目前,它返回一个空白警报.
<div id="rsvpContent">
<form id="Attendevent" action="">
<input id="attend" name="attend" type="checkBox" value="yes" /><label for="attent">Yes, I plan to attend.</label>
</form>
$("#attend").click(function(){
var form = $("#Attendevent").serialize();
$.ajax({
type:'POST',
data:{"action":"Attending","data": form },
url: "<?PHP bloginfo('url'); ?>/wp-admin/admin-ajax.PHP",
beforeSend: function(){
alert(form);
},
success: function(data) {
alert(data);
}
});
});
然后,我将此函数放置在plugin文件夹的main函数页面中:
function eventAttent() {
$wpdb->show_errors();
if($_POST['attend'] == 'yes') {
$wpdb->insert('wp_event_attendants',
array( 'event_id' => get_the_ID(),'user_id' => $current_user->ID));
echo $wpdb->print_error();
}
}
add_action('wp_ajax_Attending', 'eventAttend');
add_action('wp_ajax_nopriv_Attending', 'eventAttend');
解决方法:
尝试使用此代码.这是我测试过的代码.我可以正常工作..但是它不会处理FILE上传.
的HTML
<form id="form_name" name="form_name" >
<span id='errfrmMsg' style='margin:0 auto;'></span>
//form attributes just as input Boxe.
<input type="hidden" name="action" value="anyName" />
<input id="submit_button" onclick="submit_form();" type="button" value="Send" />
</form>
j查询
function submit_form()
{
jQuery.post(the_ajax_anyName.ajaxurl_anyName,
jQuery("#form_name").serialize(),
function(response_from_the_action_function){
jQuery("#errfrmMsg").html(response_from_the_action_function).css({"display":"block"});
}
);
}
wp_register_script("ajax-anyName", get_bloginfo('template_directory')."/js/custom_js.js", array( "jquery"));
wp_enqueue_script('ajax-anyName');
wp_localize_script("ajax-anyName","the_ajax_anyName", array("ajaxurl_anyName" => admin_url("admin-ajax.PHP")));
// add actions
add_action( "wp_ajax_anyName", "ajax_action_anyName" );
add_action( "wp_ajax_nopriv_anyName", "ajax_action_anyName" );
function ajax_action_anyName(){
//Form processing code in PHP
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。