嗨我找不到正确的语法来做这件事。
我在主页的2个不同标签中有两个表单。
form2
是form 1
我使用AJAX提交form1
$('#form-indirizzo').submit(function (e) {
e.preventDefault();
var form =$(this);
$.ajax({
type:form.attr('method'),
url:form.attr('action'),
data:form.serialize(),
success: function (data) {
-> $("#form-stufa").load(location.href+" #form-stufa>*","");
},
error: function(){
}
});
});
它会保存数据,但我还要转到form1
标签(form1有id = form-stufa)并重新加载...我试试这个
$("#form-stufa").load(location.href+" #form-stufa>*","");
重装但不起作用..
可以提供帮助
我的枝条文件:
-page-wall -->
<div id="profile-page-wall" class="stufe col s12 m12">
<!-- profile-page-wall-share -->
<div id="profile-page-wall-share" class="row">
<div class="col s12">
<ul class="tabs tab-profile z-depth-1 light-blue">
<li class="tab col s3"><a class="white-text waves-effect waves-light active" href="#UpdateStatus"><i class="mdi-editor-border-color"></i> REGISTRA STUFA</a>
</li>
<li class="tab col s3"><a class="white-text waves-effect waves-light" href="#AddPhotos"><i class="mdi-image-camera-alt"></i> Lista Stufe registrate</a>
</li>
<li class="tab col s3"><a class="white-text waves-effect waves-light" href="#CreateAlbum"><i class="mdi-image-photo-album"></i> Aggiungi Indirizzo</a>
</li>
</ul>
<!-- UpdateStatus-->
<div id="UpdateStatus" class="tab-content col s12 grey lighten-4">
{{form_start(form,{'attr':{'id':'form-stufa'}})}}
{{form_widget(form)}}
<input id="salva_stufa" class=" btn" type="submit" value="Salva" />
</div>
</div>
{{form_end(form)}}
</div>
</div>
<!-- AddPhotos -->
<div id="AddPhotos" class="tab-content col s12 grey lighten-4">
</div>
<!-- CreateAlbum -->
<div id="CreateAlbum" class="tab-content col s12 grey lighten-4">
{{form_start(form_indirizzo,{'attr':{'id':'form-indirizzo'}})}}
{{form_widget(form_indirizzo)}}
<div class="row">
<div class="col s12 m12 right-align">
<!-- Dropdown Trigger -->
<input id="salva_indirizzo" class=" btn" type="submit" value="Salva" />
</div>
</div>
{{form_end(form_indirizzo)}}
</div>
</div>
</div>
我的路线:
答案 0 :(得分:1)
试试这个。 $("#form-stufa")
如果您想点击“成功”标签,请调用JQ的click
事件。
$('#form-indirizzo').submit(function (e) {
e.preventDefault();
var form =$(this);
$.ajax({
type:form.attr('method'),
url:form.attr('action'),
data:form.serialize(),
success: function (data) {
// For redirection
setTimeout(function(){window.location.href="youURL#form-stufa"},500);
// This is for click the tab after success callback.
//setTimeout(function(){$("#form-stufa").click()},500);
},
error: function(){
}
});
});