我正在嘗試提交表格,但它不起作用。在下面的代碼中,當返回「成功」時,甚至會將「登錄」提交按鈕的顏色更改爲紅色。在Chrome控制檯它說明不了什麼,並在網絡選項卡將調用僅Ajax調用活動:未提交表格
(function ($) {
Drupal.behaviors.ajax_example = {
attach:function (context) {
jQuery('#user-login #edit-submit').click(
function(){
var login = jQuery("#user-login #edit-name").val();
var pass = jQuery("#user-login #edit-pass").val();
//make Ajax call to get authentication details
jQuery.ajax({
type:'POST',
data:{
js: 1,
login: login,
passwd:pass
},
dataType:'json',
success: function(data)
{
if(data.msg)
{
alert(data.msg);
if(data.msg == "success")
{
alert("submitted the form");
jQuery('#user-login #edit-submit').css('color', 'red');
jQuery('#user-login #edit-submit').submit();
}
}
},
url: "http://localhost/my/user/verifylogin"
});
//alert('sent data1');
return false;
})
return true;
}
}
})(jQuery);
而且Drupal的形式的HTML代碼:
<div id="content" class="column">
<div class="section"> <a id="main-content"></a>
<h1 class="title" id="page-title"> User account </h1>
<div class="tabs"> </div>
<div class="region region-content">
<div id="block-system-main" class="block block-system">
<div class="content">
<form action="/my/user" method="post" id="user-login" accept-charset="UTF-8">
<div>
<div class="form-item form-type-textfield form-item-name">
<label for="edit-name">Username <span class="form-required" title="This field is required.">*</span></label>
<input type="text" id="edit-name" name="name" value="" size="60" maxlength="60" class="form-text required">
<div class="description">please full name ending with @woodstock.ac.in</div>
</div>
<div class="form-item form-type-password form-item-pass">
<label for="edit-pass">Password <span class="form-required" title="This field is required.">*</span></label>
<input type="password" id="edit-pass" name="pass" size="60" maxlength="128" class="form-text required">
<div class="description">Enter the password that accompanies your username.</div>
</div>
<input type="hidden" name="form_build_id" value="form-gJYws5bihrq8cGOg-bZXiTcd9u5JoTqA4mqiw8nW3jc">
<input type="hidden" name="form_id" value="user_login">
<div class="form-actions form-wrapper" id="edit-actions">
<input type="submit" id="edit-submit" name="op" value="Log in" class="form-submit" style="color: red;">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
試試這個:jQuery的(「#用戶登錄,#編輯提交」)點擊() – Amit
當您使用'ajax'那麼爲什麼你需要提交它,重定向處理表單的submmition。用戶成功 –