[英]Jquery form Ajax Submit
I want to submit a form using ajax in the background. 我想在后台使用Ajax提交表单。 I tried: 我试过了:
<div class="form-horizontal" id="form">
<label for="name" class="control-label">Username</label>
<div class="controls">
<span id="name_input"><input type="text" name="name" id="medium" class='input-medium input-square'></span>
<span class="help-inline" id = "ajax_load"></span>
</div>
<div class="form-actions">
<button class="btn btn-red5" onclick="resolve()">Login</button>
<input type="reset" class='btn btn-danger' value="Reset">
</div>
</div>
And the Javascript: 和Javascript:
<script type="text/javascript">
var resolve = function () {
jAlert('test', 'test');
$('#ajax_load').html('<a href="#" class="btn btn-mini btn-square tip" title="Reloading"><img src="templates/img/ajax-loader.gif" alt=""></a>');
$.ajax( {
url : 'plugin.php?plugin=test',
type : 'post',
data: $("#form").serialize(),
success : function( resp ) {
if(resp.ajax_success == false) {
} else {
jAlert('test', 'test');
}
}
});
};
</script>
I get an alert, but there is no form submit. 我收到警报,但是没有表单提交。 I checked that with Live http headers. 我使用Live http标头进行了检查。
Why does it not submit the form? 为什么不提交表格?
#form
is not a form. 如果它不提交表单,因为#form
不是表单。 Change: 更改:
<div class="form-horizontal" id="form">
To: 至:
<form class="form-horizontal" id="form">
You need to replace the resp.ajax_success
with resp
. 您需要将resp.ajax_success
替换为resp
。 Let us also know the response of the plugin.php?plugin=test
URL. 让我们也知道plugin.php?plugin=test
URL的响应。
If you don't want the <form>
to get submitted on clicking on the Submit button, add a return false;
如果您不希望在单击“提交”按钮时提交<form>
,请添加return false;
否则, return false;
at the end of the resolve
function this way: 在resolve
函数的最后,这种方式是:
var resolve = function () {
jAlert('test', 'test');
$('#ajax_load').html('<a href="#" class="btn btn-mini btn-square tip" title="Reloading"><img src="templates/img/ajax-loader.gif" alt=""></a>');
$.ajax( {
url: 'plugin.php?plugin=test',
type: 'post',
data: $("#form").serialize(),
success: function( resp ) {
if(resp.ajax_success == false) {
} else {
jAlert('test', 'test');
}
}
});
return false;
};
its because you haven't used the form you are serializing the data from div 这是因为您没有使用过要从div序列化数据的表格
<div class="form-horizontal" id="form">
not form the form 不形成形式
should be 应该
<form class="form-horizontal" id="form">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.