如何在使用AJAX发布时检索数据我的功能是
jQuery("#wp_pass_reset").submit(function() {
var url = document.getElementById('imgurl').innerHTML;
var url2 = document.getElementById('adminurl').innerHTML;
jQuery('#result').html('<span class="loading"><img src="' + url + '/img/load.gif" /></span>').fadeIn();
var input_data = jQuery('#wp_pass_reset').serialize();
jQuery.ajax({
type: "POST",
url: url2 + 'admin-ajax.php',
data: {
action: 'resetpass_process',
value: input_data,
},
success: function(msg){
jQuery('.loading').remove();
jQuery('<div>').html(msg).appendTo('div#result').hide().fadeIn('slow');
}
});
return false;
});
这是表格:
<form class="user_form" id="wp_pass_reset" action="" method="post" name="wp_pass_reset">
<h1>
Enter Your Email or Username
</h1>
<input type="text" class="text" name="user_input" value=""><br>
<input type="hidden" name="action" value="tg_pwd_reset">
<a class="close">X</a>
<input type="hidden" name="tg_pwd_nonce" value="'.wp_create_nonce(">
<input type="submit" id="submitbtn" class="reset_password btn" name="submit" value="Reset Password">
</form>
当我使用$_POST['value']
我的所有数据检索数据时,但当我使用$_POST['user_input']
时,会发生错误。
我该怎么办?
答案 0 :(得分:1)
在这里,您要通过ajax提交表单,然后您必须在data
中传递,
data: {
action: 'resetpass_process',
value: input_data,
user_input : $('input[name="user_input"]').val(),
// add more parmeters which you need
},
答案 1 :(得分:0)
将表单字段名称中的user_input添加到数据对象:
...
data: {
action: 'resetpass_process',
value: input_data,
user_input: $('input[name="user_input"]').val()
},
...