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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题