我有一个插件可以通过ajax提交表单。
我将此作为js:
<script type=\'text/javascript\'>
$(document).ready(function() {
$(\'#form_id\').submit(function() {
e.preventDefault();
var $form = $(this);
$.post($form.attr(\'action\'), $form.serialize(), function(data) {
$(\'#feedback_id\').html(data);
});
return false;
});
});
</script>
表单的HTML如下所示:
$action=admin_url(\'admin-ajax.php\');
<form method=\'post\' action=\'$action\' id=\'form_id\'>
<ul><li><input type=\'text\' name=\'dname\' placeholder=\'Name\' />
</li><li><input type=\'email\' name=\'email\' class=\'field-style field-split align-left\' /></li>
<li>
<input type=\'hidden\' name=\'action\' value=\'php_function\'/>
<input type=\'submit\' value=\'SUBMIT\' />
</li>
</ul>
</form>
<div id=\'feedback_id\'></div>
有一个函数php\\u function()来处理表单输入。其他一切就绪:
add_action(\'wp_ajax_php_function\', \'php_function\');
add_action(\'wp_ajax_nopriv_php_function\', \'php_function\');
The output is supposed to be displayed in the div with id feedback_id but it
opens and shows up in the page \'/wp-admin/admin-ajax.php\'
我做错了什么?