我正在尝试提交表单,但它无效。在下面的代码中,当返回“成功”时,它甚至将“登录”提交按钮的颜色更改为红色。在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>
答案 0 :(得分:0)
答案 1 :(得分:0)
$( "#other" ).click(function() {
$( "#target" ).submit();
});