weixin_33739646 2016-09-27 07:37 采纳率: 0%
浏览 149

jQuery Ajax 500错误

I'm trying to connect my html with MongoDB. The data are successfully entered, but the ajax won't start. I'm going to make sure what i enter is in my database (a login form). Here's my code:

.controller('LoginCtrl', function($scope, $state, $location, $ionicPopup) {
     $scope.login = function(data) {
           var formdata = {

                   phone : $("#phone").val(),
                   pin : $("#pin").val()    
            };

            var Jformdata = JSON.stringify(formdata);
            console.log(Jformdata);

            $.ajax({

                url : "/SinarmasProject/Submit",
                context : document.body,
                type : 'POST',
                data : Jformdata,
                contentType : "application/json; charset=utf-8",
            }).done(function (response){

                if(response == "true"){
                    $location.path('/login/main/dash');
                }else if(response == "false"){
                    $scope.showAlert('Nomer Telephone dan PIN Salah');
                }

            });
}
})

The error turns out like this:

 POST http://localhost:8089/SinarmasProject/Submit 500 () jquery-3.1.0.min.js:4
send @ jquery-3.1.0.min.js:4
ajax @ jquery-3.1.0.min.js:4
$scope.login @ controllers.js:41
$parseFunctionCall @ ionic.bundle.js:20628
(anonymous function) @ ionic.bundle.js:52854
$eval @ ionic.bundle.js:22684
$apply @ ionic.bundle.js:22783
(anonymous function) @ ionic.bundle.js:52853
eventHandler @ ionic.bundle.js:11297
triggerMouseEvent @ ionic.bundle.js:2863
tapClick @ ionic.bundle.js:2852
tapMouseUp @ ionic.bundle.js:2922


EDIT: My controller.java

    package com.spring.controller;

    import java.util.List;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.data.mongodb.core.MongoTemplate;
    import org.springframework.data.mongodb.core.query.Criteria;
    import org.springframework.data.mongodb.core.query.Query;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestBody;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    import com.spring.beans.BankBean;

    @Controller
    public class controller {

        @Autowired
        private MongoTemplate mongotemplate;

        @RequestMapping(value="/BankMasuk", method= {RequestMethod.GET})
        //@ResponseBody
        public List<BankBean> BankMasuk(){
            List<BankBean> BankBean =  mongotemplate.find(new Query(), BankBean.class);
            return BankBean;
        }

        @RequestMapping(value="/Submit", method={RequestMethod.POST})
        @ResponseBody 
        public String SubmitBtn(@RequestBody BankBean bank){

            String temp;
            String string1 = bank.getPhone();
            String string2 = bank.getPin();
            Query query = new Query();
            query.addCriteria(Criteria.where("phone").is(string1));
            BankBean person = mongotemplate.findOne(query, BankBean.class);


            if(string1.equals(person.getPhone()) && string2.equals(person.getPin())){
                temp = "true";
            }else{
                temp="false";
            }


            return temp;
        }

    }

EDIT: BankBean

package com.spring.beans;

public class BankBean {
    public String phone;
    public String pin;
    public String getPhone() {
        return phone;
    }
    public void setPhone(String phone) {
        this.phone = phone;
    }
    public String getPin() {
        return pin;
    }
    public void setPin(String pin) {
        this.pin = pin;
    }
    @Override
    public String toString() {
        return "BankBean [phone=" + phone + ", pin=" + pin + "]";
    }

}
  • 写回答

1条回答 默认 最新

  • perhaps? 2016-09-27 10:23
    关注

    try to use

    .fail (function(data){
    alert(data);
    });
    

    in your jquery to know more about the error syntax of edit and fail

        .done(function (data) {
            xxx;
        }).fail(function (jqXHR, textStatus) {
            xxx;
        })
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab或python实现多个表格合并单元格
  • ¥15 gojs 点击按钮node的position位置进行改变,再次点击回到原来的位置
  • ¥15 计算决策面并仿真附上结果
  • ¥20 halcon 图像拼接
  • ¥15 webstorm上开发的vue3+vite5+typeScript打包时报错
  • ¥15 vue使用gojs,需求在link中的虚线上添加方向箭头
  • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
  • ¥15 SPSS分类模型实训题步骤
  • ¥100 求ASMedia ASM1184e & ASM1187e 芯片datasheet/规格书
  • ¥15 求解决扩散模型代码问题