发布不受支持

时间:2015-03-13 13:04:08

标签: java jquery ajax restful-url

我正在使用jquery验证插件验证表单。验证成功后,ajax调用正在db中插入数据。但这里显示帖子不受支持。

$("#evaluatorForm").validate({
// Specify the validation rules
rules: {
    employeeId: "required",
    name: "required",
    lastname: "required",
    email: {
        required: true,
        email: true
    },
    mobile:"required",
    bg:"required",
    bu:"required",

// Specify the validation error messages
messages: {
    name: "Please enter your first name",
    lastname: "Please enter your last name",
    email: "Please enter a valid email address",
},

submitHandler: function(form) {
    $.fn.serializeObject = function() {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [ o[this.name] ];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };

    var evdata = JSON.stringify($('#evaluatorForm').serializeObject());
    $.ajax({
        type : 'POST',
        url : '/nhp/rest/evaluator/insertEvaluator',
        contentType : 'application/json',
        data : evdata,
        success : function() {
            alert("Added Successfully");
            $('#evaluatorForm').trigger("reset");

        },
    });

}

}

<form role="form" id="evaluatorForm" method="POST" >
    <fieldset>
        <div class="form-group">
            <input class="form-control" placeholder="Employe Id"
                name="employeeId" type="employeeId" autofocus id="employeeId" required>
        </div>
        <div class="form-group">
            <input class="form-control" placeholder="First Name"
                name="name" type="name" autofocus id="name" required>
        </div>
        <div class="form-group">
            <input class="form-control" placeholder="Last Name" name="lastName"
                type="lastname" autofocus id="lastname" required>
        </div>
        <div class="form-group">
            <input class="form-control" placeholder="EMail" name="email"
                type="email" autofocus id="email" required>
        </div>
        <div class="form-group">
            <input class="form-control" placeholder="Contact" name="mobile"
                type="mobile" autofocus id="mobile" required>
        </div>
        <div class="form-group">
            <input class="form-control" placeholder="BG" name="bg" type="bg"
                value="" autofocus id="bg" required>
        </div>
        <div class="form-group">
        <input class="form-control" placeholder="BU" name="bu" type="bu"
                value="" autofocus id="bu" required>
        </div>
        <div class="checkbox">
            <label>Role</label> <label> <input name="te"
                type="checkbox" value="4" >TE
            </label> <label> <input name="me" type="checkbox"
                value="5">ME
            </label>
        </div>
        <input  type="submit" value="submit" id="btn" >  <input
            name="cancel" type="button" value="cancel" onclick="redirect()">
    </fieldset>
</form>
@Path("/insertEvaluator")
@POST
@Consumes(value="application/json")
public String addEvaluator(AppUser evdata) {
    Set<Role> roles= new HashSet<Role>();
 try {

     if(evdata.getMe()!=null){
    Role role=roleService.findById(evdata.getMe());
    roles.add(role);
     }
     if(evdata.getTe()!=null){
         Role role2=roleService.findById(evdata.getTe());
            roles.add(role2);
    }
    evdata.setRoles(roles);
    evaluatorService.create(evdata);


} catch (BusinessException e1) {
    e1.printStackTrace();
}

    return  "success";
}

当我点击提交按钮时,显示该帖子不受支持。

0 个答案:

没有答案